Developers
Rate Limits
The cost of using our API is based on token consumption. We charge different prices based on token category:
Prompt text, audio and image tokens - Charged at prompt token price
Cached prompt tokens - Charged at cached prompt token price
Completion tokens - Charged at completion token price
Reasoning tokens - Charged at completion token price
Visitf Model anf pricing page or general pricing.
Basic unit to calculate consumption — Tokens
A token is the basic unit of prompt size for model inference and pricing purposes. It consists of one or more character(s)/symbol(s).
When a QJS model handles your request, an input prompt will be decomposed into a list of tokens through a tokenizer. The model will then make inference based on the prompt tokens, and generate completion tokens. After the inference is completed, the completion tokens will be aggregated into a completion response sent back to you.
Our system will add additional formatting tokens to the input/output token, and if you selected a reasoning model, additional reasoning tokens will be added into the total token consumption as well. Your actual consumption will be reflected either in the usage object returned in the API response, or in Usage Explorer on the QJS Console.
You can use Tokenizer on Qjs Console to visualize tokens a given text prompt, or use Tokenize text endpoint on the API.
Text tokens
Tokens can be either of a whole word, or smaller chunks of character combinations. The more common a word is, the more likely it would be a whole token.
For example, Flint is broken down into two tokens, while Michigan is a whole token.
For a given text/image/etc. prompt or completion sequence, different tokenizers may break it down into different lengths of lists.
Different Qjs models may also share or use different tokenizers. Therefore, the same prompt/completion sequence may not have the same amount of tokens across different models.
The token count in a prompt/completion sequence should be approximately linear to the sequence length.
Image prompt tokens
Each image prompt will take between 256 to 1792 tokens, depending on the size of the image. The image + text token count must be less than the overall context window of the model.
Estimating consumption with tokenizer on xAI Console or through API
On Qjs Console, you can use the tokenizer page to estimate how many tokens your text prompt will consume. For example, the following message would consume 5 tokens (the actual consumption may vary because of additional special tokens added by the system).
Message body:
Cached prompt tokens
When you send the same prompt multiple times, we may cache your prompt tokens. This would result in reduced cost for these tokens at the cached token rate, and a quicker response.
The prompt is cached using prefix matching, using cache for the exact prefix matches in the subsequent requests. However, the cache size might be limited and distributed across different clusters.
You can also specify
x-qjs-conv-id: <A constant uuid4 ID>
in the HTTP request header, to increase the likelihood of cache hit in the subsequent requests using the same header.
Reasoning tokens
The model may use reasoning to process your request. The reasoning content is returned in the response's reasoning_content field. The reasoning token consumption will be counted separately from completion_tokens, but will be counted in the total_tokens.
The reasoning tokens will be charged at the same price as completion_tokens.
Hitting rate limits
For each tier, there is a maximum amount of requests per minute and tokens per minute. This is to ensure fair usage by all users of the system.
Once your request frequency has reached the rate limit, you will receive error code 429 in response.
You can either:
Upgrade your team to higher tiers
Change your consumption pattern to send fewer requests
Checking token consumption
In each completion response, there is a usage object detailing your prompt and completion token count. You might find it helpful to keep track of it, in order to avoid hitting rate limits or having cost surprises. You can view more details of the object on our API Reference.
The cost_in_usd_ticks field expresses the total cost to perform the inference, in 1/10,000,000,000 US dollar.
You can also check with the Qjs or OpenAI SDKs (Anthropic SDK is deprecated).
Join our Community Forum
Any other questions? Get in touch