OpenAI Chat Completion
Create chat completions using the OpenAI Chat Completion API format
Creates a completion for the chat message. The Edgee API is OpenAI-compatible and works with any model and provider. Supports both streaming and non-streaming responses.
Create a chat completion, optionally streamed as SSE. Native dispatch preserves provider-specific JSON fields when the destination supports the caller’s format. Cross-format routing converts through the Gateway’s shared representation: provider-only features are not guaranteed to survive. Support for reasoning, images, built-in tools and structured outputs depends on the destination model.
https://edgee.io/v1/chat/completionsTry this endpoint
Configure your request, then run the curl command in your terminal or send it from this page.
Comma-separated analytics tags. Trimmed and merged with body tags.
Enable debug capture for this request. Does not add a debug object to the API response.
Turn tool-result trimming on or off. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
Turn MCP tool surface reduction on or off. The threshold and resolver mode still come from the API key. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
Turn output brevity on or off. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
Session identifier used to group request usage.
Run in your terminal
Set EDGEE_API_KEY to your Gateway API key in your terminal, then copy and run this command. Gateway requests may consume credits.
curl --include --no-buffer --globoff --request POST 'https://edgee.io/v1/chat/completions' \
--header "Authorization: Bearer $EDGEE_API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"max_completion_tokens": 256
}'Send from browser
Your request is relayed through the Edgee documentation server to the Gateway. Your key is used only for this request and is not stored.
Authentication
Use an Edgee Gateway API key. Send it as Authorization: Bearer <key>.
Parameters
X-Edgee-Tagsheader · stringComma-separated analytics tags. Trimmed and merged with body tags.
X-Edgee-Debugheader · stringEnable debug capture for this request. Does not add a debug object to the API response.
X-Edgee-Compression-Tool-Result-Trimmingheader · stringTurn tool-result trimming on or off. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
X-Edgee-Compression-Tool-Surface-Reductionheader · stringTurn MCP tool surface reduction on or off. The threshold and resolver mode still come from the API key. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
X-Edgee-Compression-Brevityheader · stringTurn output brevity on or off. Overrides the API key setting for this request only. Values are case-insensitive, and a missing or invalid value keeps the key's setting.
X-Edgee-Session-Idheader · stringSession identifier used to group request usage.
Request body
Native dispatch preserves provider-specific JSON fields when the destination supports the caller’s format. Cross-format routing converts through the Gateway’s shared representation: provider-only features are not guaranteed to survive. Support for reasoning, images, built-in tools and structured outputs depends on the destination model.
modelstringrequiredModel identifier from GET /v1/models, in author/model format, or a configured global alias. Append :provider to request a specific provider route. Available models and providers depend on your key and organization policies.
messagesarrayrequiredA list of messages comprising the conversation so far. The shared typed converter also accepts input as an alias, but messages is the portable Chat Completions field for native providers.
Show schema
rolestringrequiredThe role of the message author. Required properties vary by role: - `system`, `user`, `developer`: requires `content` - `assistant`: `content` is optional (can be empty if `tool_calls` is present) - `tool`: requires `content` and `tool_call_id`
contentunionText or multimodal parts. Required for system, developer, user and tool turns; nullable/optional for assistant tool calls.
Show schema
stringtypestringrequiredtextstringrequiredcache_controlobjecttypestringrequiredimage_urlobjectrequiredtypestringrequiredimage_urlstringrequireddetailstringtypestringrequiredsourceunionrequiredProvider-native content such as audio; not guaranteed to survive cross-format conversion.
objectnamestringAn optional name for the participant. Provides the model information to differentiate between participants of the same role. Used for `system`, `user`, `assistant`, and `developer` roles.
tool_call_idstringRequired for tool messages; matches an assistant tool call ID.
refusalstringThe refusal message from the model, if any. Used for `assistant` role only.
tool_callsarrayThe tool calls made by the assistant. Used for `assistant` role only.
Show schema
idstringrequiredThe ID of the tool call.
typestringrequiredThe type of the tool call.
functionobjectrequiredShow schema
namestringrequiredThe name of the function to call.
argumentsstringrequiredThe arguments to call the function with, as JSON.
extra_contentobjectShow schema
googleobjectShow schema
thought_signaturestringOpaque provider thought signature to preserve when replaying tool calls.
cache_controlobjectAnthropic cache breakpoint metadata when translating supported system, user or tool content. Cache behavior depends on the destination provider.
reasoning_contentstringReasoning text from the provider, when exposed by the requested reasoning policy.
max_tokensintegerThe maximum number of tokens that can be generated in the chat completion.
streambooleanIf set, partial message deltas will be sent, as in OpenAI. Streamed chunks are sent as Server-Sent Events (SSE).
stream_optionsobjectOptions for streaming response.
Show schema
include_usagebooleanRequest usage in the final usage chunk before the [DONE] sentinel. It does not add a second [DONE] event.
toolsarrayFunction tools and provider-specific tools. Native paths preserve provider tool types; cross-format conversion supports only representable tool semantics.
Show schema
Standard function tool. Provider-native tool objects are also accepted by native Chat-compatible dispatch.
typestringrequiredDiscriminator for the standard function tool variant.
functionobjectrequiredShow schema
namestringrequiredThe name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
descriptionstringA description of what the function does, used by the model to choose when and how to call the function.
parametersobjectThe parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
tool_choiceunionTool selection. required/any request tool use; support for none and forced functions depends on provider and conversion path.
Show schema
none declines tools; auto lets the model choose; required/any requests tool use. Provider support varies.
none | auto | required | anystringObject form of a tool selection mode.
typestringrequiredtypestringrequiredThe type of the tool.
functionobjectrequiredShow schema
namestringrequiredThe name of the function to call.
tagsarrayOptional tags to categorize and label the request. Useful for filtering and grouping requests in analytics and logs. Can also be sent via the `x-edgee-tags` header as a comma-separated string.
Show schema
stringenable_debugbooleanEnable request debug capture. Gateway-only field; does not add debug information to the response.
max_completion_tokensintegerAlias of max_tokens. Use one spelling, not both.
temperaturenumberSampling temperature; supported range depends on the destination model.
top_pnumberNucleus sampling probability; support depends on the destination model.
reasoning_effortstringRequested effort; common values include none, minimal, low, medium, high, xhigh and max. The supported vocabulary is model-specific. Cross-format routing maps supported values and can omit unrepresentable levels.
reasoning_summarystringGateway reasoning-display override. Common values: auto, concise, detailed. For Chat Completions, positive reasoning effort normally exposes reasoning_content unless overridden.
reasoning_enabledbooleanGateway override for reasoning intent on cross-format requests; false explicitly declines reasoning.
reasoning_budget_tokensintegerLegacy Anthropic thinking budget, used only when translating to a compatible destination.
{
"model": "openai/gpt-5.2",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"max_completion_tokens": 256
}Responses
200Chat completion created successfully
application/json
idstringrequiredA unique identifier for the chat completion.
objectstringrequiredThe object type, which is always `chat.completion`.
createdintegerrequiredThe Unix timestamp (in seconds) of when the chat completion was created.
modelstringrequiredThe model used for the chat completion.
choicesarrayrequiredModel completion choices. Number of choices depends on the provider and dispatch path.
Show schema
indexintegerrequiredThe index of the choice in the list of choices.
messageobjectrequiredShow schema
rolestringrequiredThe role of the message author. Required properties vary by role: - `system`, `user`, `developer`: requires `content` - `assistant`: `content` is optional (can be empty if `tool_calls` is present) - `tool`: requires `content` and `tool_call_id`
contentunionText or multimodal parts. Required for system, developer, user and tool turns; nullable/optional for assistant tool calls.
Show schema
stringtypestringrequiredtextstringrequiredcache_controlobjecttypestringrequiredimage_urlobjectrequiredtypestringrequiredimage_urlstringrequireddetailstringtypestringrequiredsourceunionrequiredProvider-native content such as audio; not guaranteed to survive cross-format conversion.
objectnamestringAn optional name for the participant. Provides the model information to differentiate between participants of the same role. Used for `system`, `user`, `assistant`, and `developer` roles.
tool_call_idstringRequired for tool messages; matches an assistant tool call ID.
refusalstringThe refusal message from the model, if any. Used for `assistant` role only.
tool_callsarrayThe tool calls made by the assistant. Used for `assistant` role only.
Show schema
idstringrequiredThe ID of the tool call.
typestringrequiredThe type of the tool call.
functionobjectrequiredShow schema
namestringrequiredThe name of the function to call.
argumentsstringrequiredThe arguments to call the function with, as JSON.
extra_contentobjectShow schema
googleobjectcache_controlobjectAnthropic cache breakpoint metadata when translating supported system, user or tool content. Cache behavior depends on the destination provider.
reasoning_contentstringReasoning text from the provider, when exposed by the requested reasoning policy.
finish_reasonstringThe reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, or `tool_calls` if the model called a tool.
usageobjectrequiredUsage on shared converted Chat responses. Native responses preserve the provider’s usage representation, which may use prompt_tokens_details/completion_tokens_details rather than these Gateway detail fields.
Show schema
prompt_tokensintegerrequiredNumber of tokens in the prompt.
completion_tokensintegerrequiredNumber of tokens in the generated completion.
total_tokensintegerrequiredTotal number of tokens used in the request (prompt + completion).
input_tokens_detailsobjectAdditional details about input tokens.
Show schema
cached_tokensintegerNumber of cached tokens read from the prompt cache.
cache_creation_tokensintegerNumber of tokens written to the prompt cache (Anthropic-style cache creation).
cache_creation_5m_tokensintegerCache-write tokens for this TTL, omitted when zero.
cache_creation_1h_tokensintegerCache-write tokens for this TTL, omitted when zero.
output_tokens_detailsobjectAdditional details about output tokens.
Show schema
reasoning_tokensintegerNumber of reasoning tokens in the output.
compressionobjectToken compression metrics. Present in the response when token compression was applied to the request. The `usage.prompt_tokens` field reflects the compressed token count actually billed by the provider.
Show schema
saved_tokensintegerrequiredEstimated saved input tokens, calibrated to the provider token count from the ratio of local counts before and after compression.
cost_savingsintegerrequiredEstimated savings in nanodollars. Divide by 1,000,000,000 to convert to USD: 27,000,000 nanodollars = $0.027.
reductionnumberrequiredPercentage reduction: 100 × estimated saved tokens / estimated pre-compression tokens, calibrated to provider usage.
time_msintegerrequiredTime taken to perform compression, in milliseconds.
{
"id": "chatcmpl-123",
"object": "chat.completion",
"created": 1677652288,
"model": "openai/gpt-5.2",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 10,
"total_tokens": 20,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"compression": {
"saved_tokens": 450,
"cost_savings": 27000,
"reduction": 48.99884991374353,
"time_ms": 12
}
}text/event-stream
Server-Sent Events stream. Each event is a JSON object prefixed with 'data: ' and followed by two newlines. The stream consists of multiple `ChatCompletionChunk` objects, and optionally a final chunk with usage statistics if `stream_options.include_usage` is true.
string400Malformed request, invalid/disabled model or provider, or unsupported conversion.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
401Missing or invalid API credentials.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
403Key inactive, expired, model restriction or other permission failure.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
429Usage or routing-strategy budget exhausted, or provider rate limit.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
500Internal processing error.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
502Upstream provider failure.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
503Usage accounting or upstream service temporarily unavailable.
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.
529Upstream provider overloaded (when preserved by the request path).
application/json
OpenAI-shaped Gateway error. Native upstream errors can retain provider-specific details.
errorobjectrequiredShow schema
messagestringrequiredA human-readable error message.
typestringrequiredHigh-level error category.
codestringMachine-readable error code, for example unauthorized, invalid_json, bad_model_id, model_disabled, provider_disabled, usage_limit_exceeded, usage_unavailable, provider_error or internal_error. Not an exhaustive enum.
paramstringName of the request parameter that caused the error, when applicable.