The unified gateway uses standard HTTP headers for authentication, content type, and request correlation. Text endpoints and Gemini generation endpoints that support Session can enable soft sticky routing through X-Session-Id.
https://api.tokensmarket.ai/v1POST /chat/completionsThe endpoint remains fixed. Use the parameter documentation on this page to replace the model ID and request data.
${base_url}/chat/completionsThe unified gateway uses standard HTTP headers for authentication and content type, and can optionally enable sticky routing.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
Authorization | string | Yes | — | Append the current workspace API Key after Bearer. Store the full key only in server-side environment variables or a secrets manager. Options / constraints: Bearer <API_KEY>. |
Content-Type | string | Yes | application/json | Use application/json for JSON request bodies. |
X-Session-Id | string | No | — | Optional Session ID. Supported only by Chat Completions, Responses, Claude Messages, Gemini Generate Content, and Stream Generate Content. Options / constraints: Used only when neither top-level session_id nor extra_body.session_id is provided; maximum 256 characters. |
X-Client-Request-Id | string | No | — | Callers may provide a request ID; after the gateway processes the request, it echoes the value in the response. |
These are HTTP response headers, not JSON or SSE body fields. If a request does not reach the gateway, response headers are not guaranteed on network-level failures.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
X-Client-Request-Id | string | No | — | Echoed exactly when provided; not generated automatically when omitted. |
X-Upstream-Request-Id | string | No | — | Usually included for gateway request tracing; it is not the provider’s original request ID. |
Under the same model, consecutive requests carrying the same Session ID will preferentially reuse previously successful service provider channels, thereby improving the consistency of multiple rounds of dialogue and increasing the probability of upstream cache reuse. It is soft sticky: it only takes effect in channels that are still allowed and available for the current request.
Generate one stable, unique Session ID for each conversation or agent task. Reuse it for later requests and retries in the same session, and generate a new value for a new session.
When no session ID is passed, the request continues to use the platform default route. The top level session_id overrides extra_body.session_id, which in turn overrides X-Session-Id. Session IDs are only used for route association and are not used for authentication, user identification, or sharing across workspaces.
The examples use placeholders. Replace them with a currently available model ID from the model details page, and keep your API Key in a server-side environment variable.
export TOKEN_MARKET_API_KEY="<API_KEY>"
export TOKEN_MARKET_SESSION_ID="conversation-550e8400-e29b-41d4-a716-446655440000"
curl https://api.tokensmarket.ai/v1/chat/completions \
-H "Authorization: Bearer $TOKEN_MARKET_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Session-Id: $TOKEN_MARKET_SESSION_ID" \
-d '{"model":"<MODEL_ID>","messages":[{"role":"user","content":"Explain sticky routing."}]}'
curl https://api.tokensmarket.ai/v1/chat/completions \
-H "Authorization: Bearer $TOKEN_MARKET_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Session-Id: $TOKEN_MARKET_SESSION_ID" \
-d '{"model":"<MODEL_ID>","messages":[{"role":"user","content":"Explain sticky routing."},{"role":"assistant","content":"..."},{"role":"user","content":"Summarize it."}]}'