Connect
Create an account, verify your email, then open the console to create an API key. Share a separate key for each person or application; API keys only authorize inference requests.
Create account · Open console · Community node disclosure
Set CSP_API_BASE_URL to that address, including /v1, and CSP_API_KEY to your key in your server environment. Choose a model from the directory and replace MODEL_ID in examples. The console address may be different from the inference API address.
Send the key in Authorization: Bearer. Keep it on your server; do not put it in client-side JavaScript, URLs or source control. Console login cookies do not authenticate inference requests.
Chat completions
POST /v1/chat/completions returns one completed assistant response as JSON. Streaming is unavailable: omit stream or set it to false. A true value returns HTTP 400 with stream_not_supported.
curl --fail-with-body "${CSP_API_BASE_URL}/chat/completions" \
-H "Authorization: Bearer ${CSP_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @- <<'JSON'
{
"model": "MODEL_ID",
"messages": [
{
"role": "user",
"content": "Hello."
}
],
"max_completion_tokens": 256,
"stream": false
}
JSONRead the answer from choices[0].message.content. A tool response can instead contain choices[0].message.tool_calls. Check finish_reason; length means the output limit was reached.
Reasoning, unless excluded, is in choices[0].message.reasoning and choices[0].message.reasoning_details.
Responses API, embeddings, image input, strict structured outputs, log probabilities and multiple choices are unavailable.
Request parameters
Use the model directory to check supported parameters. Unknown fields are rejected; input is never silently truncated.
| Parameter | Accepted value |
|---|---|
model | Required public model ID or alias. |
messages | Required nonempty array of system, user, assistant or tool messages. Content is text or text parts. |
max_completion_tokens | Positive output limit. Defaults to the model output cap. Input plus output cap must fit the context. |
max_tokens | Legacy alias; max_completion_tokens takes precedence when both are present. |
temperature / top_p | 0–2 / 0–1. |
presence_penalty / frequency_penalty | −2 to 2. |
stop | A string or one to four strings. |
seed | An integer. |
n / stream | Only 1 / false, or omit them. |
tools, tool_choice, parallel_tool_calls | Function definitions, auto / none / required / a named function, and a boolean. The caller executes tools. |
response_format | Type text or json_object. JSON schema / strict mode is unavailable. |
reasoning | Object with enabled, effort, max_tokens and exclude. Set effort or max_tokens, not both; the budget must be below the output limit. effort: none | minimal | low | medium | high | xhigh | max |
reasoning_effort / include_reasoning | Older forms; the reasoning object takes precedence. |
messages[].reasoning / reasoning_content, reasoning_details | Assistant messages only: earlier reasoning text and details, sent back as received. |
user | Optional opaque end-user identifier. It is not forwarded to the supply. |
Tools and JSON mode
A tool-capable model returns function names and JSON argument strings. Validate those arguments before executing your application function, then send the assistant tool_calls and the corresponding tool result with its tool_call_id in the next request.
curl --fail-with-body "${CSP_API_BASE_URL}/chat/completions" \
-H "Authorization: Bearer ${CSP_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @- <<'JSON'
{
"model": "MODEL_ID",
"messages": [
{
"role": "user",
"content": "Hello."
}
],
"max_completion_tokens": 256,
"stream": false,
"tools": [
{
"type": "function",
"function": {
"name": "get_time",
"description": "Read the current time for a time zone.",
"parameters": {
"type": "object",
"properties": {
"timezone": {
"type": "string"
}
},
"required": [
"timezone"
]
}
}
}
],
"tool_choice": "auto"
}
JSONFor JSON mode, ask the model for JSON and use response_format. Validate the returned JSON against your application requirements.
curl --fail-with-body "${CSP_API_BASE_URL}/chat/completions" \
-H "Authorization: Bearer ${CSP_API_KEY}" \
-H 'Content-Type: application/json' \
--data-binary @- <<'JSON'
{
"model": "MODEL_ID",
"messages": [
{
"role": "user",
"content": "Return a JSON object with a greeting field."
}
],
"max_completion_tokens": 256,
"stream": false,
"response_format": {
"type": "json_object"
}
}
JSONModel list
GET /v1/models requires an API key and returns the gateway's currently usable model list. The website directory publishes catalog definitions and prices; endpoint availability can change independently.
curl --fail-with-body "${CSP_API_BASE_URL}/models" \
-H "Authorization: Bearer ${CSP_API_KEY}"Read model IDs from data[].id. Pricing in that API is expressed in dollars per token; the website displays dollars per million tokens.
Usage and billing
The gateway reserves balance using estimated input and the requested output limit before inference. It settles the completed usage and releases the remainder. A balance or API key quota too small for this reservation returns HTTP 402.
Successful responses contain usage.prompt_tokens, usage.completion_tokens and usage.total_tokens. Usage may be estimated when supply reporting is missing or inconsistent. The console's request detail is the billing record.
usage.completion_tokens_details.reasoning_tokens counts reasoning tokens. They are part of completion_tokens and billed as output, even when hidden.
When routing uses a fallback, the response model can differ from your requested model. Billing follows the requested model's price.
Errors and retries
Errors have an error object with type, message, param and code. Save the X-Request-Id response header when requesting support or checking a request in the console.
| HTTP status | Action |
|---|---|
| 400 | Correct the request, supported fields, context size or stream setting before retrying. |
| 401 / 403 | Check the API key, its status and account access. |
| 402 | Check available balance, key quota and requested output limit. |
| 404 | Check the model ID and current availability. |
| 429 | Respect Retry-After. Rate limit headers show the current request window. |
| 500 / 502 / 503 / 504 | Record the request ID. Retry only with bounded backoff when your application can tolerate a new request. |
A client retry is a new inference request and may be charged again. If a connection drops before you receive the result, check the console's usage records before repeating a costly request.