v39

latestOpenAPI 3.1.0raw.githubusercontent.com2025-11-2613102194.9 KB
v1
chat

Create Chat Completion

Create a chat completion.

Generates a model response for the given conversation and configuration. Supports OpenAI-compatible parameters and provider-specific extensions.

Headers:

  • Authorization: bearer key for the calling account.
  • Optional BYOK or provider headers if applicable.

Behavior:

  • If multiple models are supplied, the first one is used, and the agent may hand off to another model.
  • Tools may be invoked on the server or signaled for the client to run.
  • Streaming responses emit incremental deltas; non-streaming returns a single object.
  • Usage metrics are computed when available and returned in the response.

Responses:

  • 200 OK: JSON completion object with choices, message content, and usage.
  • 400 Bad Request: validation error.
  • 401 Unauthorized: authentication failed.
  • 402 Payment Required or 429 Too Many Requests: quota, balance, or rate limit issue.
  • 500 Internal Server Error: unexpected failure.

Billing:

  • Token usage metered by the selected model(s).
  • Tool calls and MCP sessions may be billed separately.
  • Streaming is settled after the stream ends via an async task.

Example (non-streaming HTTP): POST /v1/chat/completions Content-Type: application/json Authorization: Bearer <key>

{ "model": "provider/model-name", "messages": [{"role": "user", "content": "Hello"}] }

200 OK { "id": "cmpl_123", "object": "chat.completion", "choices": [ {"index": 0, "message": {"role": "assistant", "content": "Hi there!"}, "finish_reason": "stop"} ], "usage": {"prompt_tokens": 3, "completion_tokens": 4, "total_tokens": 7} }

Example (streaming over SSE): POST /v1/chat/completions Accept: text/event-stream

data: {"id":"cmpl_123","choices":[{"index":0,"delta":{"content":"Hi"}}]} data: {"id":"cmpl_123","choices":[{"index":0,"delta":{"content":" there!"}}]} data: [DONE]

post/v1/chat/completions

Request body

audioobject nullable

Parameters for audio output. Required when audio output is requested with `mo...

frequency_penaltynumber nullable

Number between -2.0 and 2.0. Positive values penalize new tokens based on the...

function_callstring nullable

Deprecated in favor of tool_choice. Controls which (if any) function is ca...

logit_biasobject nullable

Modify the likelihood of specified tokens appearing in the completion. Accep...

logprobsboolean nullable

Whether to return log probabilities of the output tokens or not. If true, ret...

max_completion_tokensinteger nullable

Maximum tokens in completion (newer parameter name)

max_tokensinteger nullable

Maximum tokens in completion

metadataobject nullable

Set of 16 key-value pairs that can be attached to an object. This can be usef...

modalitiesstring[] nullable

Output types that you would like the model to generate. Most models are capab...

ninteger nullable

How many chat completion choices to generate for each input message. Note tha...

parallel_tool_callsboolean nullable

Whether to enable parallel tool calls (Anthropic uses inverted polarity)

presence_penaltynumber nullable

Number between -2.0 and 2.0. Positive values penalize new tokens based on whe...

prompt_cache_keystring nullable

Used by OpenAI to cache responses for similar requests to optimize your cache...

prompt_cache_retentionstring nullable

The retention policy for the prompt cache. Set to 24h to enable extended pr...

reasoning_effortstring nullable

Constrains effort on reasoning for [reasoning models](https://platform.openai...

safety_identifierstring nullable

A stable identifier used to help detect users of your application that may be...

seedinteger nullable

Random seed for deterministic output

service_tierstring nullable

Service tier for request processing

storeboolean nullable

Whether or not to store the output of this chat completion request for use in...

streamboolean nullable

Enable streaming response

stream_optionsobject nullable

Options for streaming response. Only set this when you set stream: true.

temperaturenumber nullable

Sampling temperature (0-2 for most providers)

top_kinteger nullable

Top-k sampling parameter

top_logprobsinteger nullable

An integer between 0 and 20 specifying the number of most likely tokens to re...

top_pnumber nullable

Nucleus sampling threshold

userstring nullable

This field is being replaced by safety_identifier and prompt_cache_key. U...

verbositystring nullable

Constrains the verbosity of the model's response. Lower values will result in...

web_search_optionsobject nullable

This tool searches the web for relevant results to use in a response. Learn m...

cachedContentstring nullable

Optional. The name of the content [cached](https://ai.google.dev/gemini-api/d...

deferredboolean nullable

If set to true, the request returns a request_id. You can then get the de...

generation_configobject nullable

Generation parameters wrapper (Google-specific)

prompt_modeobject nullable

Allows toggling between the reasoning mode and no system prompt. When set to ...

safe_promptboolean nullable

Whether to inject a safety prompt before all conversations.

search_parametersobject nullable

Set the parameters to be used for searched data. If not set, no data will be ...

stop_sequencesstring[] nullable

Custom text sequences that will cause the model to stop generating. Our mode...

tool_configobject nullable

Tool calling configuration (Google-specific)

guardrailsobject[] nullable

Content filtering and safety policy configuration.

handoff_configobject nullable

Configuration for multi-model handoffs.

model_attributesobject nullable

Model attributes for routing. Maps model IDs to attribute dictionaries with values in [0.0, 1.0].

agent_attributesobject nullable

Agent attributes. Values in [0.0, 1.0].

max_turnsinteger nullable

Maximum conversation turns.

automatic_tool_executionboolean

Execute tools server-side. If false, returns raw tool calls for manual handling.

Example request

{
  "model_attributes": {
    "gpt-5": {
      "accuracy": 0.95,
      "speed": 0.6
    }
  },
  "agent_attributes": {
    "accuracy": 0.9,
    "complexity": 0.8
  },
  "max_turns": 5
}

Response

JSON or SSE stream of ChatCompletionChunk events

idstring required

A unique identifier for the chat completion.

createdinteger required

The Unix timestamp (in seconds) of when the chat completion was created.

modelstring required

The model used for the chat completion.

service_tier'auto' | 'default' | 'flex' | 'scale' | 'priority' nullable

Specifies the processing type used for serving the request.

  • If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
  • If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
  • If set to 'flex' or 'priority', then the request will be processed with the corresponding service tier.
  • When not set, the default behavior is 'auto'.

When the service_tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.

system_fingerprintstring

This fingerprint represents the backend configuration that the model runs with.

Can be used in conjunction with the seed request parameter to understand when backend changes have been made that might impact determinism.

object'chat.completion' required

The object type, which is always chat.completion.

tools_executedstring[] nullable

List of tool names that were executed server-side (e.g., MCP tools). Only present when tools were executed on the server rather than returned for client-side execution.

mcp_server_errorsobject nullable

Information about MCP server failures, if any occurred during the request. Contains details about which servers failed and why, along with recommendations for the user. Only present when MCP server failures occurred.

Example response

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "The next Warriors game is tomorrow at 7:30 PM.",
        "role": "assistant"
      }
    }
  ],
  "created": 1677652288,
  "id": "chatcmpl-123",
  "model": "gpt-4o-mini",
  "object": "chat.completion",
  "tools_executed": [
    "search_events",
    "get_event_details"
  ],
  "usage": {
    "completion_tokens": 12,
    "prompt_tokens": 9,
    "total_tokens": 21
  }
}