Skip to main content
Model APIs bill by token and enforce request and token rate limits for each model. You can set a workspace budget, inspect token usage, and attribute costs by API key, user, model, or service tier. Choose the task you need:

Pricing

Model APIs bill per million input and output tokens. Rates vary by model. See the Model APIs pricing page for current prices.

Cached input tokens

Baseten serves prompt tokens from the KV cache at a discounted rate when a request reuses a cached prefix. Caching is automatic and requires no request flags. Cached and uncached input tokens count equally toward token rate limits. Caching generated output for the next request depends on the model’s cache configuration and whether the prefix remains in the cache. Check usage.prompt_tokens_details.cached_tokens to measure how much of each prompt came from the cache.

Session affinity

Session affinity identifies requests that belong to the same conversation or agent task. Baseten routes requests with the same session ID to the same replica, where the shared prompt prefix is more likely to remain in the KV cache. Coding agents like Claude Code, Codex, and OpenCode provide session IDs that Baseten recognizes, so you don’t need to configure session affinity. For other clients, send x-session-affinity with every related request:
To connect Claude Code, Codex CLI, or another coding agent to Baseten, see Set up coding agents. Keep the value stable for one conversation or agent task, including its subagents. Use a different value for unrelated work so Baseten can distribute requests across replicas. Use an opaque value, such as a UUID, or hash an internal conversation ID before sending it. Baseten recommends at most about 60 requests per minute for one session. Session affinity controls routing, not conversation state. Continue to include the conversation messages in each request.

Check cache reuse

To measure cache reuse, send requests with the same long prompt prefix and session affinity ID, then inspect usage.prompt_tokens_details.cached_tokens. The count is part of usage.prompt_tokens; don’t add it to the input total. Set BASETEN_API_KEY to your API key and install uv to run the example. It sends two billable requests with a shared policy document. Save it as check_cache.py:
check_cache.py
Run it with the OpenAI SDK:
Example output:
In the second request, 2,816 of the 2,824 input tokens came from the cache. The remaining 8 input tokens use the uncached rate. Exact counts vary by model, prompt, and cache state. A positive cached count confirms reuse for that request. A zero count means that request reported no cached input. When later requests still report zero:
  • Keep the shared prefix identical, including system instructions and tool definitions.
  • Reuse the same session affinity ID for related requests.
  • Check that you use the same model and that the prompt has a substantial shared prefix. A short greeting isn’t a useful cache test.
Session affinity improves the chance of reuse but doesn’t reserve a replica or guarantee a cache hit. The prefix must still be present in the model’s cache.

Rate limits

Baseten enforces the following limits for each Model API:

Check your current limits

To retrieve the limits for a model in your workspace, set BASETEN_API_KEY to your API key, then call Get a Model API by name:
Replace zai-org%2FGLM-5.3 with your model’s URL-encoded slug (/ becomes %2F). Read threshold for the REQUEST and TOKEN entries with unit: "MINUTE" to find RPM and TPM. Your returned limits can differ from this example and the account defaults below. You can also inspect the rate limit response headers on inference responses to see your limits and the remaining allowance.

Default limits by account tier

These are account defaults. A model, service tier, or organization-specific configuration can set different limits. Check your current limits for the model you call.

Account verification and higher limits

To confirm whether your Basic account is verified and which verification steps apply, contact support. Include your workspace name, sign-in email, the model slug, and the limits returned by the model details request. Keep the full API key out of your message. To request more capacity for your workload, submit a rate limit increase request. Include the model, expected requests and tokens per minute, and whether traffic arrives steadily or in bursts. Confirm the effective limits again after your account or model configuration changes. Changing a request’s max_tokens controls its output length; it doesn’t raise the workspace’s TPM limit. Fast variants have separate slugs and rate limits, so check the limits for the exact variant you call.

Rate limit response headers

Rate limits replenish continuously instead of resetting at fixed intervals. Send requests at a steady rate, and use exponential backoff after a 429 Too Many Requests response. A 529 Overloaded response means that the Model API has no available serving capacity. This response can occur even when your organization remains within its rate limits. See 529: overloaded for retry guidance.

Budgets

Set a monthly budget to receive email notifications as workspace spend approaches the configured amount. If you enforce the budget, Baseten rejects Model API requests after the workspace reaches it. Budget enforcement does not affect Dedicated Inference or Training.

Usage

For Chat Completions, read request token totals from usage.prompt_tokens and usage.completion_tokens. The accepted_prediction_tokens and rejected_prediction_tokens fields in completion_tokens_details report speculative-decoding statistics. They aren’t separate billing counters, so don’t add them to completion usage or use them to calculate charges. Rejected predictions can exceed the completion token count. Choose a usage interface based on how you plan to use the data: The CLI and REST API return input, cached input, uncached input, and output token counts alongside request counts. Select 1m, 1h, or 1d buckets, then group or filter results by API key, user, or model. Baseten retains Model API usage data for 92 days. Queries for older buckets return no results.
Show one day of usage by model:
Use baseten model-api usage to change the time range, bucket width, grouping, filters, or output format.
When you group usage by user, Baseten attributes personal API keys and OAuth credentials to their owner. Credentials without user scope return a null user ID. For continuous monitoring, export Model API metrics to Prometheus:
  • baseten_model_api_tokens_total separates uncached input, cached input, and output tokens.
  • baseten_model_api_inference_requests_total counts requests by status code.
See Model API metrics for metric and label definitions.

Costs

baseten org billing usage reports total Model API cost as part of the workspace billing summary. The GET /v1/billing/model_apis endpoint returns daily Model API costs and can group them by API key, user, model, or service tier. Both calculate costs from recorded token usage and the model price that applied when each request ran.
Show the total Model API cost for the last seven days:
The CLI returns the Model API total from the workspace billing summary. See baseten org billing usage for date-range and output options.

Cost breakdowns

Omit group_by to return one workspace subtotal per day. Repeat it to break down costs by API key, user, model, or service tier. Filter results with api_key_prefixes, user_ids, models, and service_tiers. Pass API key prefixes, not full API keys. Each result represents one observed combination of the dimensions you request. Baseten omits combinations without usage, so the number of results can differ between days. When you group by user, Baseten attributes personal API keys and OAuth credentials to their owner. Credentials without user scope return a null user ID.

Cost response fields

The API returns one bucket for each UTC day, from midnight inclusive to the next midnight exclusive. It orders buckets from oldest to newest without gaps. A day without matching usage has an empty results array. When you group by API key, api_key_prefixes contains the attributed prefix in a one-item array. Fields for dimensions you don’t request return null. Requested API key, user, and service-tier fields can also return null when attribution is unavailable. subtotal is an exact decimal string in USD, such as "0.00000123". Parse it with a decimal or fixed-point type to preserve fractional-cent amounts.

Cost history and pagination

Cost data begins on August 5, 2026, at 20:45 UTC. The August 5 bucket includes only usage recorded after that time. The API rejects an earlier start_date.
The endpoint includes start_date and excludes end_date. start_date defaults to the previous UTC date, and end_date defaults to the day after the current UTC date. If you omit both parameters, the response includes yesterday and the current day. Baseten can add costs to the current-day bucket as it records usage. A date range can cover up to 90 days. limit controls the number of daily buckets in a page. It defaults to 7 and has a maximum of 31. When pagination.has_more is true, pass pagination.cursor in the next request. The cursor retains the original date range, grouping, filters, and limit. When you pass a cursor, the endpoint ignores other query parameters. Cost subtotals exclude credits, adjustments, taxes, and other invoice terms. Use the billing usage summary endpoint to review combined Dedicated Inference, Training, and Model API costs. Your invoice is the final record of billed charges. See the Model API costs reference for filters, pagination, attribution rules, and response fields.