API GUIDES

Tokens & usage

Read usage fields and understand the difference between request size and plan allowance.

On this pageWhat counts as a token?Read the usage objectContext size and allowanceCached input and plan tokensKeep requests efficient
Connection details · Use your provider’s key, base URL and model ID. DS-sub account and API access are not connected yet.

What counts as a token?#

A tokenizer splits text into units processed by the model. A token is not a fixed number of words or characters. Code, punctuation, languages and model tokenizers can produce different counts for similar-looking text.

Use returned usage for a request-level view rather than character estimates. For billing questions, also check the provider's accounting rules and usage records.

Read the usage object#

For a non-streaming Chat Completions response, inspect the usage object. Field availability can vary by provider.

FieldMeaning
prompt_tokensTokens in the request context
completion_tokensTokens generated for the response
total_tokensCombined prompt and completion usage

Messages from earlier turns count as input again when sent in a new request. Tool definitions, tool results and other supported inputs can also contribute to context usage.

Context size and allowance#

Context size limits how much a model can process in one request. A plan allowance limits consumption over a time window. A request can fit the model's context but exceed your plan's remaining allowance, or fail the context limit while you still have allowance left.

Cached input and plan tokens#

An official API cache discount concerns the provider's price calculation. Plan tokens may use a different conversion rule. Do not subtract cached tokens or assume they are free unless your plan explicitly says so. See usage and limits for the site's reference plan rules.

Keep requests efficient#

  • Send only the context needed for the current task.
  • Avoid repeatedly attaching large generated files or logs.
  • Keep output requests focused and set supported output limits where appropriate.
  • Compare a small representative workload before changing model or plan.

Reference: DeepSeek token usage documentation.

Guide updated November 5, 2026 · All tutorials