Advanced usage
Streaming output, function calling, JSON mode, and cached-token pricing.
Streaming output (SSE)
Add "stream": true to the request body to get an SSE streaming response with the same event format as OpenAI:
- Each event is a
data: {JSON}line, ending withdata: [DONE]. - The platform automatically injects
stream_options.include_usage, so the final chunk carriesusage, and billing is based on thatusage. - Streaming response headers don't include X-Cost-Yuan; a single generation lasts up to 5 minutes by default, so split longer output into multiple requests.
Function calling
The tools, tool_choice, and parallel_tool_calls parameters in the request body are passed through to the model provider as-is, and the model's tool_calls are returned verbatim in message—the platform doesn't parse them.
Whether these are supported depends on the model you call; see the capability tags in Models.
JSON mode
response_format: { "type": "json_object" } is passed through as-is, constraining the model to output valid JSON. Support likewise depends on the model.
Cached-token pricing
usage.prompt_tokens_details distinguishes cached hits (cached_tokens) from cache writes (cache_write_tokens). These segments are priced separately at the model's cache price, while the remaining input is charged at the normal input price. If a model has no cache price configured, the input price applies.
Cache prices are shown on each model's detail page in Models. Requests with repeated prefixes (such as a long system prompt or few-shot examples) are more likely to hit the cache, which can substantially lower input costs.
Reliability and rate limiting
The platform maintains an upstream channel priority for each model. If the primary channel fails, the gateway automatically fails over to a backup channel with no code changes on the caller's side; the switch happens inside the request, so the only thing you'll notice is slightly higher latency to the first token.
All calls share platform-level rate and budget protection. When rate limiting is triggered, the API returns 429—retry later. To request higher quotas, submit a support ticket to contact us.