Create a chat completion
https://api.respan.ai/api/chat/completionsSends a chat completion request through the Respan gateway with automatic logging. Accepts OpenAI chat completion parameters and Respan options for fallbacks, caching, and prompt management.
Pass Respan parameters in top-level body fields, under respan_params, or as base64-encoded JSON in the X-Data-Respan-Params header. If the same field is sent more than one way, respan_params takes precedence over the header, and both take precedence over a top-level field. The exception is variables: top-level variables are merged key by key over the variables from respan_params or the header. respan_params, keywordsai_params, and the decoded header must each be a JSON object; a top-level respan_params may also be a JSON string that decodes to one. Any other value is ignored, and so are the header’s parameters: the request is served, but none of those parameters apply. Fields sent at the top level still apply. With the OpenAI SDK, use extra_body.
For legacy compatibility, keywordsai_params is merged into respan_params, and X-Data-Keywordsai-Params is still accepted and renamed internally.
Servers
https://api.respan.ai — Respan API Server
Authentication
RespanApiKey
Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.
HTTP scheme: bearer; format: Respan API key.
Authorization: Bearer $RESPAN_API_KEYHeaders
X-Data-Respan-Params string OptionalX-Data-Keywordsai-Params is still accepted.X-Respan-Route-Provider string OptionalExample:
"vertex_ai"X-Respan-Beta string OptionalRequest body
A request body is required.
application/json
$ object Required body
{"model":"gpt-6-luna","messages":[{"role":"user","content":"Reply with exactly ok."}],"max_tokens":32,"temperature":0,"reasoning_effort":"none"}messages array<object> Required in parent
role (system, user, assistant, tool) and content.Example:
[{"role":"user","content":"Reply with exactly ok."}]messages[] object Array item
messages[].role string Required in parentAllowed:
"system", "user", "assistant", "tool"messages[].content string or array<object> Required in parent
messages[].content (oneOf 1) string Schema variantmessages[].content (oneOf 2) array<object> Schema variant
messages[].content (oneOf 2)[] object Array itemmessages[].name string Optionalmessages[].tool_call_id string Optionalmodel string Required in parentstream boolean OptionalDefault:
falseExample:
falsetools array<object> Optional
tools[] object Array itemtool_choice object Optional"none" = no tools, "auto" = model decides, or specify a tool object.frequency_penalty number OptionalExample:
0max_tokens number OptionalExample:
1024temperature number OptionalDefault:
1Example:
0.7n number Optionaln.Default:
1Example:
1logprobs boolean OptionalDefault:
falseecho boolean Optionalstop array<string> Optional
stop[] string Array itempresence_penalty number OptionalExample:
0logit_bias object Optionalresponse_format object Optional{"type": "json_schema", "json_schema": {...}} for structured output, or {"type": "json_object"} for JSON mode.parallel_tool_calls boolean Optionalload_balance_group object Optional{"group_id": "..."} to route through a configured group.fallback_models array<string> Optional
Example:
["gpt-6-luna","claude-haiku-5-5"]fallback_models[] string Array itemcustomer_credentials object Optionalcredential_override object Optionalcache_enabled boolean Optionalcache_ttl number Optionalcache_ttl is served from the cache for at most 30 minutes.Example:
3600cache_options object Optional
cache_by_customer, is_cached_by_model, omit_log.cache_options.cache_by_customer boolean OptionalDefault:
falsecache_options.is_cached_by_model boolean OptionalDefault:
falsecache_options.omit_log boolean OptionalDefault:
falseprompt object Optionalprompt_id (required), variables (template variables), version (number, or "latest" for draft), echo (return rendered prompt), override (use override_params), override_params (OpenAI params to override), schema_version (1 = legacy, 2 = prompt config wins). See Prompt management.retry_params object Optionalretry_params (retry_enabled, num_retries, retry_after) applies only to POST /api/responses. See Retries and fallback.disable_log boolean Optionaltrue, omits input/output from the log. Metrics (tokens, cost, latency) are still recorded.Example:
falsemodel_name_map object Optionalmodels array<string> Optional
models[] string Array itemexclude_providers array<string> Optional
Default:
[]exclude_providers[] string Array itemexclude_models array<string> Optional
Default:
[]exclude_models[] string Array itemmetadata object OptionalExample:
{"feature":"chat","env":"production"}custom_identifier string OptionalExample:
"order_456"customer_identifier string OptionalMaximum length:
254Example:
"user_123"customer_params object Optionalcustomer_identifier (takes precedence over the top-level customer_identifier), name and email (logged with the request, and saved on the customer when Respan first sees it), and rate_limit (requests per minute for this customer, overriding your organization’s customer rate limit; requests over it get 429). Budget fields sent here aren’t saved or enforced. Set budgets with Update a user.request_breakdown boolean OptionalDefault:
falsepositive_feedback boolean Optionaltrue = liked, false = disliked.load_balance_models array<object> Optional
model, weight, and optional credentials.load_balance_models[] object Array itemthread_identifier string Optionalthread_identifier are grouped together.Example:
"thread_abc"properties object Optionalmetadata which coerces to strings.retries integer OptionalDefault:
0Example:
2weight number OptionalExample:
1span_name string OptionalExample:
"chat_completion"respan_params object OptionalOpenAPI request schema
{
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"system",
"user",
"assistant",
"tool"
],
"description": "Message role."
},
"content": {
"description": "Message content. Use a string for text-only requests, or an array of content parts for multimodal requests.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object"
}
}
]
},
"name": {
"type": "string",
"description": "Optional participant name."
},
"tool_call_id": {
"type": "string",
"description": "Required for tool response messages."
}
}
},
"description": "Array of messages in the conversation. Each message has `role` (`system`, `user`, `assistant`, `tool`) and `content`.",
"example": [
{
"role": "user",
"content": "Reply with exactly ok."
}
]
},
"model": {
"type": "string",
"description": "Model to use. See [Models](https://platform.respan.ai/platform/models) for available options.",
"example": "gpt-6-luna"
},
"stream": {
"type": "boolean",
"description": "Stream back partial progress token by token as server-sent events.",
"default": "false",
"example": false
},
"tools": {
"type": "array",
"items": {
"type": "object"
},
"description": "Tools the model may call. Currently only functions are supported."
},
"tool_choice": {
"type": "object",
"description": "Controls tool selection. `\"none\"` = no tools, `\"auto\"` = model decides, or specify a tool object."
},
"frequency_penalty": {
"type": "number",
"description": "Penalizes tokens based on frequency in text so far (-2 to 2).",
"example": 0
},
"max_tokens": {
"type": "number",
"description": "Maximum tokens to generate.",
"example": 1024
},
"temperature": {
"type": "number",
"description": "Sampling temperature (0-2). Higher = more random.",
"default": 1,
"example": 0.7
},
"n": {
"type": "number",
"description": "Number of completions to generate. Note: costs multiply with `n`.",
"default": 1,
"example": 1
},
"logprobs": {
"type": "boolean",
"description": "Return log probabilities of output tokens.",
"default": "false"
},
"echo": {
"type": "boolean",
"description": "Echo back the prompt in addition to the completion"
},
"stop": {
"type": "array",
"items": {
"type": "string"
},
"description": "Stop sequences where generation halts."
},
"presence_penalty": {
"type": "number",
"description": "Penalizes tokens already present in text (-2 to 2).",
"example": 0
},
"logit_bias": {
"type": "object",
"description": "Used to modify the probability of tokens appearing in the response"
},
"response_format": {
"type": "object",
"description": "Output format. Set `{\"type\": \"json_schema\", \"json_schema\": {...}}` for structured output, or `{\"type\": \"json_object\"}` for JSON mode."
},
"parallel_tool_calls": {
"type": "boolean",
"description": "Enable parallel function calling during tool use."
},
"load_balance_group": {
"type": "object",
"description": "Load balance group selection. Use `{\"group_id\": \"...\"}` to route through a configured group."
},
"fallback_models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Backup models (ranked by priority) if the primary model fails.",
"example": [
"gpt-6-luna",
"claude-haiku-5-5"
]
},
"customer_credentials": {
"type": "object",
"description": "Per-customer LLM provider credentials. Keys are provider names, values are API keys."
},
"credential_override": {
"type": "object",
"description": "One-off credential overrides per provider. Overrides uploaded provider keys for this request only."
},
"cache_enabled": {
"type": "boolean",
"description": "Enable response caching. See [Caching](/docs/documentation/features/gateway/caching).",
"example": false
},
"cache_ttl": {
"type": "number",
"description": "How long a cached response is served, in seconds. A response stored without `cache_ttl` is served from the cache for at most 30 minutes.",
"example": 3600
},
"cache_options": {
"type": "object",
"description": "Cache behavior options. Properties: `cache_by_customer`, `is_cached_by_model`, `omit_log`.",
"properties": {
"cache_by_customer": {
"type": "boolean",
"default": false,
"description": "Partition cache entries by customer identifier."
},
"is_cached_by_model": {
"type": "boolean",
"default": false,
"description": "Partition cache entries by model name."
},
"omit_log": {
"type": "boolean",
"default": false,
"description": "Suppress log creation for cache hits."
}
}
},
"prompt": {
"type": "object",
"description": "Prompt template config. Properties: `prompt_id` (required), `variables` (template variables), `version` (number, or `\"latest\"` for draft), `echo` (return rendered prompt), `override` (use override_params), `override_params` (OpenAI params to override), `schema_version` (`1` = legacy, `2` = prompt config wins). See [Prompt management](/docs/documentation/features/prompt-management/advanced)."
},
"retry_params": {
"type": "object",
"description": "Has no effect on this endpoint: chat completions always uses your organization's retry settings. Per-request `retry_params` (`retry_enabled`, `num_retries`, `retry_after`) applies only to `POST /api/responses`. See [Retries and fallback](/docs/documentation/features/gateway/retries)."
},
"disable_log": {
"type": "boolean",
"description": "When `true`, omits input/output from the log. Metrics (tokens, cost, latency) are still recorded.",
"example": false
},
"model_name_map": {
"type": "object",
"description": "Azure deployment name mapping. Maps your custom Azure deployment names to standard model names."
},
"models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Model list for LLM router selection."
},
"exclude_providers": {
"type": "array",
"items": {
"type": "string"
},
"description": "Providers to exclude from routing. All models under excluded providers are skipped.",
"default": "[]"
},
"exclude_models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Specific models to exclude from routing.",
"default": "[]"
},
"metadata": {
"type": "object",
"description": "Custom key-value metadata attached to the span.",
"example": {
"feature": "chat",
"env": "production"
}
},
"custom_identifier": {
"type": "string",
"description": "Indexed custom tag for fast querying.",
"example": "order_456"
},
"customer_identifier": {
"type": "string",
"description": "End user identifier for analytics and budgets.",
"maxLength": 254,
"example": "user_123"
},
"customer_params": {
"type": "object",
"description": "Customer details. Properties: `customer_identifier` (takes precedence over the top-level `customer_identifier`), `name` and `email` (logged with the request, and saved on the customer when Respan first sees it), and `rate_limit` (requests per minute for this customer, overriding your organization's customer rate limit; requests over it get `429`). Budget fields sent here aren't saved or enforced. Set budgets with [Update a user](/docs/apis/users/update-user)."
},
"request_breakdown": {
"type": "boolean",
"description": "Return response metrics summary in the response body. For streaming, metrics appear in the final chunk.",
"default": "false"
},
"positive_feedback": {
"type": "boolean",
"description": "User feedback. `true` = liked, `false` = disliked."
},
"load_balance_models": {
"type": "array",
"items": {
"type": "object"
},
"description": "Inline load balancing options. Each item can include `model`, `weight`, and optional `credentials`."
},
"thread_identifier": {
"type": "string",
"description": "Conversation thread ID. Spans with the same `thread_identifier` are grouped together.",
"example": "thread_abc"
},
"properties": {
"type": "object",
"description": "Typed metadata preserving native types (numbers, booleans, nested objects). Unlike `metadata` which coerces to strings."
},
"retries": {
"type": "integer",
"description": "Has no effect: chat completions always uses your organization's retry settings. See [Retries and fallback](/docs/documentation/features/gateway/retries).",
"default": 0,
"example": 2
},
"weight": {
"type": "number",
"description": "Load balancing weight.",
"example": 1
},
"span_name": {
"type": "string",
"description": "Custom span name for tracing.",
"example": "chat_completion"
},
"respan_params": {
"type": "object",
"description": "Namespaced container for all Respan parameters. Alternative to passing them at top level. Must be a JSON object, or a JSON string that decodes to one. A list, number or boolean is ignored and none of its params apply."
}
},
"required": [
"messages",
"model"
],
"example": {
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}
}Example
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}Examples
Chat completion
Request
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}Response
{
"body": {
"id": "chatcmpl_abc123",
"object": "chat.completion",
"created": 1709155200,
"model": "gpt-6-luna",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "ok"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13
}
}
}cURL
curl --request POST 'https://api.respan.ai/api/chat/completions' \
--header "Authorization: Bearer $RESPAN_API_KEY" \
--header 'Content-Type: application/json' \
--data @- <<'JSON'
{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}
JSONPython
import json
import os
import urllib.request
payload = json.loads(r'''{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}''')
request = urllib.request.Request(
"https://api.respan.ai/api/chat/completions",
data=json.dumps(payload).encode(),
headers={
"Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(request) as response:
print(json.load(response))TypeScript
const response = await fetch("https://api.respan.ai/api/chat/completions", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RESPAN_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());Python SDK (respan-api)
import json
import os
from respan import RespanClient
client = RespanClient(respan_api_key=os.environ["RESPAN_API_KEY"])
payload = json.loads(r'''{
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}''')
response = client.gateway.create_chat_completion(
**payload,
)
print(response)TypeScript SDK (@respan/respan-api)
import { RespanClient } from "@respan/respan-api";
const apiKey = process.env.RESPAN_API_KEY!;
const client = new RespanClient({
respanApiKey: apiKey,
authorization: `Bearer ${apiKey}`,
});
const response = await client.gateway.createChatCompletion({
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
});
console.log(response);Responses
200
Successful response for Create chat completion
application/json
$ object Body
id string Required in parentobject string Required in parent"chat.completion"created integer Required in parentmodel string Required in parentchoices array<object> Required in parent
choices[] object Array item
choices[].index integer Optionalchoices[].message object Optional
choices[].message.role string Optional"assistant"choices[].message.content string Optional"ok"choices[].finish_reason string Optional"stop"usage object Optional
usage.prompt_tokens integer Optionalusage.completion_tokens integer Optionalusage.total_tokens integer OptionalOpenAPI response schema
{
"type": "object",
"required": [
"id",
"object",
"created",
"model",
"choices"
],
"properties": {
"id": {
"type": "string",
"description": "Chat completion ID."
},
"object": {
"type": "string",
"example": "chat.completion"
},
"created": {
"type": "integer",
"description": "Unix timestamp for when the completion was created."
},
"model": {
"type": "string",
"description": "Model used for the completion."
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {
"type": "integer"
},
"message": {
"type": "object",
"properties": {
"role": {
"type": "string",
"example": "assistant"
},
"content": {
"type": "string",
"example": "ok"
}
}
},
"finish_reason": {
"type": "string",
"example": "stop"
}
}
}
},
"usage": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "integer"
},
"completion_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
}
}
}
}Example
{
"id": "chatcmpl_abc123",
"object": "chat.completion",
"created": 1709155200,
"model": "gpt-6-luna",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "ok"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13
}
}text/event-stream
$ string Bodystream is true.OpenAPI response schema
{
"type": "string",
"description": "OpenAI-compatible server-sent events when `stream` is true."
}400
Invalid request or preprocessing failure.
application/json
$ object Body
error object Required in parent
error.message string Required in parenterror.type string Required in parenterror.param any or null Optionalerror.code any or null OptionalOpenAPI response schema
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}401
No usable key for the model. The code is activation_required when your organization has no credits and no provider key for the model.
403
The API key is missing, invalid or expired.
application/json
$ object Body
detail string Required in parentOpenAPI response schema
{
"type": "object",
"required": [
"detail"
],
"properties": {
"detail": {
"type": "string"
}
}
}Example
{
"detail": "Your API key is invalid or expired, please check your API key in the platform settings."
}404
The model isn’t available to your organization.
application/json
$ object Body
error object Required in parent
error.message string Required in parenterror.type string Required in parenterror.param any or null Optionalerror.code any or null OptionalOpenAPI response schema
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}424
The upstream model provider failed.
application/json
$ object Body
error object Required in parent
error.message string Required in parenterror.type string Required in parenterror.param any or null Optionalerror.code any or null OptionalOpenAPI response schema
{
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}OpenAPI source
The operation and referenced components below retain the complete OpenAPI definitions, including constraints and examples.
OpenAPI operation
{
"summary": "Create a chat completion",
"operationId": "createChatCompletion",
"tags": [
"Gateway"
],
"description": "Sends a chat completion request through the Respan gateway with automatic logging. Accepts [OpenAI chat completion parameters](https://platform.openai.com/docs/apis/chat) and Respan options for fallbacks, caching, and prompt management.\n\nPass Respan parameters in top-level body fields, under `respan_params`, or as base64-encoded JSON in the `X-Data-Respan-Params` header. If the same field is sent more than one way, `respan_params` takes precedence over the header, and both take precedence over a top-level field. The exception is `variables`: top-level `variables` are merged key by key over the `variables` from `respan_params` or the header. `respan_params`, `keywordsai_params`, and the decoded header must each be a JSON object; a top-level `respan_params` may also be a JSON string that decodes to one. Any other value is ignored, and so are the header's parameters: the request is served, but none of those parameters apply. Fields sent at the top level still apply. With the OpenAI SDK, use `extra_body`.\n\nFor legacy compatibility, `keywordsai_params` is merged into `respan_params`, and `X-Data-Keywordsai-Params` is still accepted and renamed internally.",
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"messages": {
"type": "array",
"items": {
"type": "object",
"required": [
"role",
"content"
],
"properties": {
"role": {
"type": "string",
"enum": [
"system",
"user",
"assistant",
"tool"
],
"description": "Message role."
},
"content": {
"description": "Message content. Use a string for text-only requests, or an array of content parts for multimodal requests.",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "object"
}
}
]
},
"name": {
"type": "string",
"description": "Optional participant name."
},
"tool_call_id": {
"type": "string",
"description": "Required for tool response messages."
}
}
},
"description": "Array of messages in the conversation. Each message has `role` (`system`, `user`, `assistant`, `tool`) and `content`.",
"example": [
{
"role": "user",
"content": "Reply with exactly ok."
}
]
},
"model": {
"type": "string",
"description": "Model to use. See [Models](https://platform.respan.ai/platform/models) for available options.",
"example": "gpt-6-luna"
},
"stream": {
"type": "boolean",
"description": "Stream back partial progress token by token as server-sent events.",
"default": "false",
"example": false
},
"tools": {
"type": "array",
"items": {
"type": "object"
},
"description": "Tools the model may call. Currently only functions are supported."
},
"tool_choice": {
"type": "object",
"description": "Controls tool selection. `\"none\"` = no tools, `\"auto\"` = model decides, or specify a tool object."
},
"frequency_penalty": {
"type": "number",
"description": "Penalizes tokens based on frequency in text so far (-2 to 2).",
"example": 0
},
"max_tokens": {
"type": "number",
"description": "Maximum tokens to generate.",
"example": 1024
},
"temperature": {
"type": "number",
"description": "Sampling temperature (0-2). Higher = more random.",
"default": 1,
"example": 0.7
},
"n": {
"type": "number",
"description": "Number of completions to generate. Note: costs multiply with `n`.",
"default": 1,
"example": 1
},
"logprobs": {
"type": "boolean",
"description": "Return log probabilities of output tokens.",
"default": "false"
},
"echo": {
"type": "boolean",
"description": "Echo back the prompt in addition to the completion"
},
"stop": {
"type": "array",
"items": {
"type": "string"
},
"description": "Stop sequences where generation halts."
},
"presence_penalty": {
"type": "number",
"description": "Penalizes tokens already present in text (-2 to 2).",
"example": 0
},
"logit_bias": {
"type": "object",
"description": "Used to modify the probability of tokens appearing in the response"
},
"response_format": {
"type": "object",
"description": "Output format. Set `{\"type\": \"json_schema\", \"json_schema\": {...}}` for structured output, or `{\"type\": \"json_object\"}` for JSON mode."
},
"parallel_tool_calls": {
"type": "boolean",
"description": "Enable parallel function calling during tool use."
},
"load_balance_group": {
"type": "object",
"description": "Load balance group selection. Use `{\"group_id\": \"...\"}` to route through a configured group."
},
"fallback_models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Backup models (ranked by priority) if the primary model fails.",
"example": [
"gpt-6-luna",
"claude-haiku-5-5"
]
},
"customer_credentials": {
"type": "object",
"description": "Per-customer LLM provider credentials. Keys are provider names, values are API keys."
},
"credential_override": {
"type": "object",
"description": "One-off credential overrides per provider. Overrides uploaded provider keys for this request only."
},
"cache_enabled": {
"type": "boolean",
"description": "Enable response caching. See [Caching](/docs/documentation/features/gateway/caching).",
"example": false
},
"cache_ttl": {
"type": "number",
"description": "How long a cached response is served, in seconds. A response stored without `cache_ttl` is served from the cache for at most 30 minutes.",
"example": 3600
},
"cache_options": {
"type": "object",
"description": "Cache behavior options. Properties: `cache_by_customer`, `is_cached_by_model`, `omit_log`.",
"properties": {
"cache_by_customer": {
"type": "boolean",
"default": false,
"description": "Partition cache entries by customer identifier."
},
"is_cached_by_model": {
"type": "boolean",
"default": false,
"description": "Partition cache entries by model name."
},
"omit_log": {
"type": "boolean",
"default": false,
"description": "Suppress log creation for cache hits."
}
}
},
"prompt": {
"type": "object",
"description": "Prompt template config. Properties: `prompt_id` (required), `variables` (template variables), `version` (number, or `\"latest\"` for draft), `echo` (return rendered prompt), `override` (use override_params), `override_params` (OpenAI params to override), `schema_version` (`1` = legacy, `2` = prompt config wins). See [Prompt management](/docs/documentation/features/prompt-management/advanced)."
},
"retry_params": {
"type": "object",
"description": "Has no effect on this endpoint: chat completions always uses your organization's retry settings. Per-request `retry_params` (`retry_enabled`, `num_retries`, `retry_after`) applies only to `POST /api/responses`. See [Retries and fallback](/docs/documentation/features/gateway/retries)."
},
"disable_log": {
"type": "boolean",
"description": "When `true`, omits input/output from the log. Metrics (tokens, cost, latency) are still recorded.",
"example": false
},
"model_name_map": {
"type": "object",
"description": "Azure deployment name mapping. Maps your custom Azure deployment names to standard model names."
},
"models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Model list for LLM router selection."
},
"exclude_providers": {
"type": "array",
"items": {
"type": "string"
},
"description": "Providers to exclude from routing. All models under excluded providers are skipped.",
"default": "[]"
},
"exclude_models": {
"type": "array",
"items": {
"type": "string"
},
"description": "Specific models to exclude from routing.",
"default": "[]"
},
"metadata": {
"type": "object",
"description": "Custom key-value metadata attached to the span.",
"example": {
"feature": "chat",
"env": "production"
}
},
"custom_identifier": {
"type": "string",
"description": "Indexed custom tag for fast querying.",
"example": "order_456"
},
"customer_identifier": {
"type": "string",
"description": "End user identifier for analytics and budgets.",
"maxLength": 254,
"example": "user_123"
},
"customer_params": {
"type": "object",
"description": "Customer details. Properties: `customer_identifier` (takes precedence over the top-level `customer_identifier`), `name` and `email` (logged with the request, and saved on the customer when Respan first sees it), and `rate_limit` (requests per minute for this customer, overriding your organization's customer rate limit; requests over it get `429`). Budget fields sent here aren't saved or enforced. Set budgets with [Update a user](/docs/apis/users/update-user)."
},
"request_breakdown": {
"type": "boolean",
"description": "Return response metrics summary in the response body. For streaming, metrics appear in the final chunk.",
"default": "false"
},
"positive_feedback": {
"type": "boolean",
"description": "User feedback. `true` = liked, `false` = disliked."
},
"load_balance_models": {
"type": "array",
"items": {
"type": "object"
},
"description": "Inline load balancing options. Each item can include `model`, `weight`, and optional `credentials`."
},
"thread_identifier": {
"type": "string",
"description": "Conversation thread ID. Spans with the same `thread_identifier` are grouped together.",
"example": "thread_abc"
},
"properties": {
"type": "object",
"description": "Typed metadata preserving native types (numbers, booleans, nested objects). Unlike `metadata` which coerces to strings."
},
"retries": {
"type": "integer",
"description": "Has no effect: chat completions always uses your organization's retry settings. See [Retries and fallback](/docs/documentation/features/gateway/retries).",
"default": 0,
"example": 2
},
"weight": {
"type": "number",
"description": "Load balancing weight.",
"example": 1
},
"span_name": {
"type": "string",
"description": "Custom span name for tracing.",
"example": "chat_completion"
},
"respan_params": {
"type": "object",
"description": "Namespaced container for all Respan parameters. Alternative to passing them at top level. Must be a JSON object, or a JSON string that decodes to one. A list, number or boolean is ignored and none of its params apply."
}
},
"required": [
"messages",
"model"
],
"example": {
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}
},
"example": {
"model": "gpt-6-luna",
"messages": [
{
"role": "user",
"content": "Reply with exactly ok."
}
],
"max_tokens": 32,
"temperature": 0,
"reasoning_effort": "none"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Successful response for Create chat completion",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"id",
"object",
"created",
"model",
"choices"
],
"properties": {
"id": {
"type": "string",
"description": "Chat completion ID."
},
"object": {
"type": "string",
"example": "chat.completion"
},
"created": {
"type": "integer",
"description": "Unix timestamp for when the completion was created."
},
"model": {
"type": "string",
"description": "Model used for the completion."
},
"choices": {
"type": "array",
"items": {
"type": "object",
"properties": {
"index": {
"type": "integer"
},
"message": {
"type": "object",
"properties": {
"role": {
"type": "string",
"example": "assistant"
},
"content": {
"type": "string",
"example": "ok"
}
}
},
"finish_reason": {
"type": "string",
"example": "stop"
}
}
}
},
"usage": {
"type": "object",
"properties": {
"prompt_tokens": {
"type": "integer"
},
"completion_tokens": {
"type": "integer"
},
"total_tokens": {
"type": "integer"
}
}
}
}
},
"example": {
"id": "chatcmpl_abc123",
"object": "chat.completion",
"created": 1709155200,
"model": "gpt-6-luna",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "ok"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 1,
"total_tokens": 13
}
}
},
"text/event-stream": {
"schema": {
"type": "string",
"description": "OpenAI-compatible server-sent events when `stream` is true."
}
}
}
},
"400": {
"description": "Invalid request or preprocessing failure.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}
}
}
},
"401": {
"description": "No usable key for the model. The code is `activation_required` when your organization has no credits and no provider key for the model."
},
"403": {
"$ref": "#/components/responses/InvalidApiKey"
},
"404": {
"description": "The model isn't available to your organization.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}
}
}
},
"424": {
"description": "The upstream model provider failed.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"error"
],
"properties": {
"error": {
"type": "object",
"required": [
"message",
"type"
],
"properties": {
"message": {
"type": "string"
},
"type": {
"type": "string"
},
"param": {
"nullable": true
},
"code": {
"nullable": true
}
}
}
}
}
}
}
}
},
"parameters": [
{
"name": "X-Data-Respan-Params",
"in": "header",
"required": false,
"schema": {
"type": "string"
},
"description": "Base64-encoded JSON object of Respan parameters. Legacy `X-Data-Keywordsai-Params` is still accepted."
},
{
"name": "X-Respan-Route-Provider",
"in": "header",
"required": false,
"schema": {
"type": "string"
},
"description": "Pin the request to a specific provider without changing the model slug. Use the provider ID shown for that model in the model catalog.",
"example": "vertex_ai"
},
{
"name": "X-Respan-Beta",
"in": "header",
"required": false,
"schema": {
"type": "string"
},
"description": "Comma-separated beta feature flags. Available: token-breakdown-2026-03-26, env-scoped-integrations-2026-03-28"
}
],
"security": [
{
"RespanApiKey": []
}
]
}OpenAPI path metadata
{}Referenced OpenAPI components
{
"responses": {
"InvalidApiKey": {
"description": "The API key is missing, invalid or expired.",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"detail"
],
"properties": {
"detail": {
"type": "string"
}
}
},
"example": {
"detail": "Your API key is invalid or expired, please check your API key in the platform settings."
}
}
}
}
},
"securitySchemes": {
"RespanApiKey": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "Respan API key",
"description": "Use your Respan API key for Respan API authentication. Enter only the Respan API key value; clients send Authorization: Bearer <RESPAN_API_KEY>. For /api/responses, provider credentials such as Perplexity, OpenAI, or Azure OpenAI go in Settings -> Providers or respan_params.credential_override in the request body, not in this authentication field.",
"x-fern-bearer": {
"name": "respanApiKey",
"env": "RESPAN_API_KEY"
}
}
}
}