BasicRouter Docs
Quickstart
BasicRouter gives production teams one stable API for model access, routing, fallback, usage tracking, and credit-based billing. LLM token supply is sourced from trusted enterprise cloud original-provider accounts, with privacy protection, high stability, and request traceability built into the gateway.
https://api.basicrouter.ai/apihttps://api.basicrouter.ai/api/v1https://api.basicrouter.ai/api/v1Authorization: Bearer <key>Create an API key
Create a BasicRouter API key in the console. Keep the key on your server and never expose it in browser or mobile client code.
Recommended key strategy:
| Key type | Recommended usage |
|---|---|
| Development key | Local development, staging, testing, and prototypes. |
| Production key | Backend production workloads only. |
| Integration key | Dedicated key for tools such as Cursor, Claude Code, Codex, Hermes, or OpenClaw. |
| Customer / tenant key | Optional key isolation for enterprise customers, tenant traffic, or business units. |
Rotate keys when team access changes. Revoke keys that are no longer used.
Point your SDK at BasicRouter
Most OpenAI-compatible clients only need a new base URL and API key.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.BASICROUTER_API_KEY,
baseURL: "https://api.basicrouter.ai/api/v1"
});Send a chat completion
curl --request POST \
--url https://api.basicrouter.ai/api/v1/chat/completions \
--header "Authorization: Bearer $BASICROUTER_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"model": "claude-sonnet-5",
"messages": [
{ "role": "user", "content": "Explain BasicRouter in one sentence." }
]
}'Check usage and balance
curl --request GET \
--url https://api.basicrouter.ai/api/v1/billing/balance \
--header "Authorization: Bearer $BASICROUTER_API_KEY"Model Discovery
Use the Models page or the Models API to inspect available text models. Model metadata includes vendor, serving provider, modality, context length, supported API families, supported capabilities, availability, account-level limits, and credit pricing.
Endpoint: GET /v1/models Purpose: List models available to the current account.
curl --request GET \
--url https://api.basicrouter.ai/api/v1/models \
--header "Authorization: Bearer $BASICROUTER_API_KEY"Capability matrix
| Capability | Description | Commonly used by |
|---|---|---|
streaming | Supports server-sent event streaming. | Chat apps, coding agents, real-time UX. |
tool_calling | Supports tool or function calling. | Agents, workflow automation, coding assistants. |
structured_outputs | Supports schema-constrained or JSON outputs. | Data extraction, workflow automation, enterprise apps. |
json_mode | Can return JSON-formatted output. | Lightweight structured responses. |
vision | Accepts image input. | Multimodal chat, UI analysis, document screenshots. |
prompt_caching | Supports cached input or context reuse. | Long-context agents, repeated system prompts. |
reasoning | Supports explicit reasoning controls where available. | Complex planning, coding, analysis workflows. |
logprobs | Supports token probability output. | Evaluation, ranking, advanced NLP workflows. |
API family compatibility matrix
| API family | Text | Vision input | Tool calling | Structured output | Streaming | Notes |
|---|---|---|---|---|---|---|
| OpenAI Chat Completions | Yes | Model-dependent | Model-dependent | Model-dependent | Yes | Best default for OpenAI-compatible agents and SDKs. |
| OpenAI Responses | Yes | Model-dependent | Model-dependent | Model-dependent | Yes | Recommended for newer OpenAI-style agent workflows. |
| Anthropic Messages | Yes | Model-dependent | Model-dependent | Model-dependent | Yes | Best for Claude-compatible clients and Claude Code. |
| BasicRouter image generation | No | Model-dependent | No | No | No | Uses async task polling or webhook. |
| BasicRouter video generation | No | Model-dependent | No | No | No | Uses async task polling or webhook. |
Authentication
Every API request uses a bearer token. Store keys in server-side environment variables, rotate them when team access changes, and log request IDs for debugging.
| Header | Value | Notes |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | Required for every request. |
Content-Type | application/json | Required for JSON request bodies. |
Key security recommendations
- Keep API keys on the server. Do not expose keys in browser or mobile client code.
- Use separate keys for development, staging, production, and third-party integrations.
- Scope keys by environment, service, customer, or tenant when available.
- Rotate keys after employee departures, vendor access changes, or suspected leakage.
- Store keys in secret managers or environment variables, not source code.
Using the Console
The BasicRouter Console is the operational control plane for API access, model availability, routing policies, usage visibility, and billing administration. It gives account administrators a centralized view of keys, models, requests, credits, and account-level controls for production model traffic.
Managing API keys
Create, rotate, revoke, and label API keys from the console. Use separate keys for development, staging, production, and individual services so usage can be audited and isolated by environment or application.
| Practice | Description |
|---|---|
| Separate environments | Use different API keys for development, staging, and production traffic. |
| Use descriptive labels | Label keys by application, service, environment, or integration. |
| Rotate regularly | Rotate keys when access changes or credentials may have been exposed. |
| Avoid client-side exposure | Keep API keys on server-side systems only. Do not expose keys in browser or mobile client code. |
| Monitor key usage | Review request volume, credit consumption, and error patterns by key. |
Model list
Use the Models page to review models available to the account. Each model entry may include vendor, serving provider, modality, supported API families, context length, capability flags, availability status, and pricing information.
| Filter | Purpose |
|---|---|
| Vendor | Filter by model vendor such as OpenAI, Anthropic, Google, Qwen, DeepSeek, or other providers. |
| Provider | Filter by serving provider or cloud provider. |
| Modality | Filter by text, image, video, embedding, audio, or multimodal support. |
| Capability | Filter by streaming, tool calling, structured outputs, vision, prompt caching, or reasoning support. |
| Availability | Identify models that are currently available to the account. |
For production applications, verify model capabilities before enabling traffic. Some parameters and features are model-dependent and may not be supported across all API families.
Usage & logs
The Usage & Logs view provides operational visibility into API traffic. Teams can inspect request volume, selected models, resolved routing targets, credit consumption, latency, error codes, and request IDs.
- Troubleshoot failed requests.
- Identify high-cost workloads.
- Compare model usage across applications and environments.
- Validate routing and fallback behavior.
- Investigate latency or provider availability issues.
- Provide request IDs when contacting support.
Each API response includes or exposes a BasicRouter request ID. Store this ID in your application logs to make production debugging and support escalation more efficient.
Fallback
Fallback is BasicRouter's resilience mechanism. When the primary model or routing policy fails, the system automatically switches to a backup model to keep processing the request. This keeps your application responsive and minimizes the risk of service disruption.
Fallback acts like a safety net, keeping your application running smoothly even when a model failure, quota limit, or network fluctuation occurs.
Why fallback matters
In production, model services can run into a number of unpredictable issues:
- Model service failure: the upstream API becomes temporarily unavailable or times out.
- Performance fluctuation: high model load leads to slow or failed responses.
- Routing failure: all candidate models selected by smart routing become unavailable.
Fallback keeps your application available by providing a reliable backup path.
Core advantages
| Advantage | Description |
|---|---|
| High availability | Automatic failover keeps the service running and reduces the impact of outages. |
| Transparent switching | The system switches models automatically — no application code changes required. |
| Flexible configuration | Supports both per-request and account-level configuration for different use cases. |
| Cost optimization | Choose a more cost-effective model as the fallback to control emergency costs. |
| Centralized management | Configure once at the account level and it applies automatically to every request. |
Global fallback model configuration
BasicRouter supports setting a global fallback model from the console backend. All requests automatically use this model as a backup when they fail.
How to configure it:
- Go to the BasicRouter strategy settings page.
- Find the Default Fallback Model setting.
- Select your global fallback model from the dropdown list.
- Save the setting to apply it immediately.
Advantages of global configuration:
- No code changes required: configure once and it applies globally, with no need to repeat the setting on every request.
- Centralized management: manage the fallback policy in one place for easier adjustment and monitoring.
- Simplified maintenance: reduces code complexity and the chance of configuration errors.
- Flexible override: request-level fallback configuration takes priority and can override the global setting for specific scenarios.
Request-level fallback configuration
For specific business scenarios, you can specify a fallback model on an individual request to override the global configuration.
Specify the fallback model with the router.fallBackModels parameter:
{
"model": "claude-sonnet-4",
"messages": [
{
"role": "user",
"content": "Explain what quantum computing is"
}
],
"router": {
"fallBackModels": ["glm-5.2"]
}
}Priority rules
When multiple fallback configurations are present, priority runs from highest to lowest:
- Request-level
router.fallBackModels: the fallback model specified on an individual request. - Global Default Fallback Model: the global fallback model configured in the console.
- No fallback: if neither is configured, the request returns an error on failure.
- If all fallback models fail, the system returns the failure reason from the last model attempted.
- When a fallback occurs, the response indicates the model actually used, making it easy to monitor and analyze.
Account administration
Depending on account type, the console may include account-level model enablement, reseller or distributor controls, billing configuration, and access settings. Administrators can use these controls to align model access, usage visibility, and billing responsibility with applications, customer accounts, or business units.
Production operations checklist
| Item | Recommendation |
|---|---|
| API keys | Use dedicated production keys with clear labels. |
| Models | Confirm model availability, pricing, context length, and required capabilities. |
| Routing | Configure routing aliases or fallback policies for critical workloads. |
| Logs | Ensure request IDs are captured in application logs. |
| Billing | Confirm wallet balance, plan status, and credit deduction rules. |
| Rate limits | Review account-level RPM, TPM, concurrency, and media task limits. |
| Alerts | Monitor usage growth, credit balance, errors, and provider availability. |
Billing & Credits
BasicRouter uses a credit-based billing model across text, image, video, and other supported model workloads. Credits provide a unified unit for multi-model and multi-provider usage so teams can manage consumption consistently across modalities and API families.
Detailed model pricing is available on the Models page or through model metadata APIs. Pricing may vary by model, provider, modality, resolution, token type, output length, task duration, account type, and commercial agreement.
Top up & wallet
Accounts may add pay-as-you-go wallet credits for flexible usage. Wallet credits are used after monthly plan credits and resource packs have been consumed, unless a custom billing rule applies to the account.
Wallet credits do not expire unless otherwise specified in applicable commercial terms. Service fee is charged when recharging the pay-as-you-go wallet.
Monthly plans and resource packs
Each user or account can select one active monthly plan. Monthly plans provide a defined amount of usage capacity, commercial terms, and account-level access configuration for the billing period.
Users can also buy multiple resource packs for additional usage capacity. Resource packs can separate committed usage from pay-as-you-go wallet balance and are useful for high-volume text, image, video, or dedicated workload usage.
Deduction order
Unless custom billing rules are configured, credits are deducted in the following order:
| Priority | Credit source | Description |
|---|---|---|
| 1 | Monthly plan | Included monthly usage capacity is consumed first. |
| 2 | Resource packs | Additional purchased packs are consumed after monthly plan credits. |
| 3 | Pay-as-you-go wallet | Wallet balance is consumed after plan and resource pack credits. |
For accounts with custom commercial terms, deduction order, expiration rules, included usage, and pricing may differ. Account-specific rules are shown in the console or provided through the commercial agreement.
Custom pricing
Pricing can be customized for each user or account. Enterprise customers, reseller accounts, distributor accounts, and high-volume customers may be eligible for custom pricing. Contact sales for a quote.
Custom pricing can be configured by account, model, provider, modality, region, usage volume, or commercial agreement. When custom pricing is enabled, the console and billing APIs reflect account-specific pricing and deduction rules where available.
Pricing units
Different model modalities use different measurement units. BasicRouter converts these units into credits according to the model’s pricing rules.
| Modality | Common pricing basis |
|---|---|
| Text | Input tokens, output tokens, cached read tokens, cached write tokens, reasoning tokens, or model-specific token categories. |
| Image | Model, resolution, number of generated images, input image usage, editing mode, or quality setting. |
| Video | Model, output resolution, generated seconds, aspect ratio, input image or video usage, and task type. |
| Embeddings | Input tokens or number of embedding records. |
| Audio | Input duration, output duration, transcription length, or model-specific audio units. |
Pricing units may vary by model. Always refer to the model detail page or pricing metadata before enabling a model in production.
Usage attribution
BasicRouter usage can be reviewed by account, API key, model, modality, or time range. This allows teams to attribute cost to applications, environments, customers, or internal business units.
| Dimension | Description |
|---|---|
| API key | Group usage by application, service, or environment. |
| Model | Compare cost and volume by selected model. |
| Resolved model | Review the actual model used after routing or fallback. |
| Modality | Separate text, image, video, embedding, and audio usage. |
| Time range | Review daily, monthly, or custom reporting periods. |
| Metadata | Group usage by custom request metadata such as customer ID, tenant ID, user ID, or environment. |
Credit balance
Check how many credits are available across your account. The balance is split into three wallets that are deducted in order: the monthly plan allowance, purchased resource packs, and the pay-as-you-go wallet. A combined resource total (monthly plan + resource packs, excluding pay-as-you-go) is also available for tracking included usage separately from top-up spending.
To retrieve this programmatically, see GET /v1/billing/balance in the API Reference.
Usage details
Review a paginated, chronological list of individual usage records for reporting, monitoring, and internal cost allocation. Each record shows the model, model type (text, image, or video), the credits deducted, and a breakdown of which wallet each deduction was drawn from. Results can be filtered to a specific time range.
To retrieve this programmatically, see GET /v1/usage in the API Reference.
Transaction history
Use transaction history to review credit movements, including top-ups, plan allocations, resource pack grants, usage deductions, adjustments, and administrative corrections.
To retrieve this programmatically, see GET /v1/billing/transactions in the API Reference.
Failed requests and refunds
Validation errors, authentication errors, and permission errors are generally not billed because no model execution occurs. Requests that reach an upstream model or generate partial output may consume credits depending on the model, provider, and response state.
For async image and video tasks, billing behavior depends on whether the task was accepted, started, completed, failed, or cancelled. The task detail response includes usage information when credits have been consumed.
Top-ups, monthly plans, resource packs, and consumed credits are non-refundable unless otherwise specified in the applicable commercial agreement or required by law.
Operational
Errors
BasicRouter returns stable error codes so applications can handle retries, fallbacks, billing issues, and debugging consistently.
Provider-compatible endpoints try to preserve the original API family's error shape where possible. BasicRouter-native endpoints use the BasicRouter error object.
HTTP status and error code mapping
| HTTP status | Error type | Example codes | Retry |
|---|---|---|---|
| 400 | invalid_request_error | invalid_request, unsupported_parameter, invalid_messages, invalid_image_url | No |
| 401 | authentication_error | missing_api_key, invalid_api_key | No |
| 402 | billing_error | insufficient_credits, payment_required, quota_exceeded | No |
| 403 | permission_error | model_access_denied, endpoint_access_denied, key_scope_denied | No |
| 404 | not_found_error | model_not_found, response_not_found, task_not_found | No |
| 408 | timeout_error | gateway_timeout, provider_timeout | Yes |
| 409 | conflict_error | idempotency_conflict, task_already_cancelled | Depends |
| 422 | validation_error | schema_validation_failed, unsupported_modality | No |
| 429 | rate_limit_error | account_rpm_exceeded, account_tpm_exceeded, provider_rate_limited | Yes |
| 500 | internal_error | internal_error | Yes |
| 502 | provider_error | provider_bad_gateway, provider_invalid_response | Yes |
| 503 | service_unavailable | model_unavailable, provider_unavailable, insufficient_capacity | Yes |
| 504 | timeout_error | provider_timeout, gateway_timeout | Yes |
Common error codes
| Code | Meaning | Recommended action |
|---|---|---|
missing_api_key | No API key was provided. | Add the Authorization header. |
invalid_api_key | API key is invalid or revoked. | Create or rotate the API key. |
model_not_found | Model ID does not exist or is not enabled for the account. | Check the Models page or call GET /v1/models. |
model_access_denied | API key or account does not have access to the model. | Enable the model or contact admin. |
unsupported_parameter | Request includes a parameter unsupported by the selected endpoint or model. | Remove the parameter or choose a compatible model. |
unsupported_modality | Input or output modality is not supported by the selected model. | Choose a model that supports the modality. |
account_rpm_exceeded | Account requests per minute limit exceeded. | Retry with backoff or request higher limits. |
account_tpm_exceeded | Account tokens per minute limit exceeded. | Retry with backoff, reduce tokens, or request higher limits. |
provider_rate_limited | Upstream provider rate limited the request. | Retry or enable fallback. |
insufficient_credits | Account has insufficient credits. | Top up wallet, buy a pack, or upgrade plan. |
provider_timeout | Upstream provider did not respond in time. | Retry or enable fallback. |
model_unavailable | Model is temporarily unavailable. | Retry or use a routing alias. |
content_policy_error | Request or output was blocked by a safety policy. | Modify input or choose a suitable workflow. |
