The unified gateway uses standard HTTP headers for authentication and content type, and can optionally enable sticky routing for the same business session 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 | — | An optional sticky-routing key. When one business session reuses the same value, the gateway prefers the provider that served the previous successful request. Options / constraints: Up to 256 characters. Header names are case-insensitive. |
For the same model, consecutive requests with the same X-Session-Id prefer the provider that served the previous successful request. This improves consistency in multi-turn conversations and increases Prompt Cache hit rates. If the preferred provider is unavailable, the gateway can still select another available provider under the existing fallback policy.
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.
Without X-Session-Id, the request continues to use default platform routing. A Session ID only correlates routing; it does not authenticate users, identify users, or enable sharing across workspaces, and callers must not treat it as a permanent provider binding.
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."}]}'