Skip to navigation

Create Chat Completion

View as MarkdownOpen in Claude

OpenAI-compatible Chat Completions. Send a model from GET /v1/models and a list of messages. Add a web_search or web_extract tool to let the router run You.com web searches and page fetches for the model. Parameters are forwarded to the model, and models differ in what they accept.

Authentication

AuthorizationBearer

Your You.com API key, sent as Authorization: Bearer <key>. Get a key in the “Get your API key” section of the documentation.

Headers

x-request-idstringOptional

A client-chosen request ID for tracing. The router generates one when the header is absent or invalid, and returns it in the response.

x-session-idstringOptional<=256 characters
A conversation identifier of up to 256 characters. Requests that share a session ID are kept together where possible.

Request

This endpoint expects an object.
modelstringRequired

A model ID from GET /v1/models.

messageslist of objectsRequired
The conversation so far, in OpenAI Chat Completions format.
streambooleanOptional

Stream the response as server-sent events.

stream_optionsobjectOptional

Options for streamed responses, such as include_usage.

temperaturedoubleOptional
Sampling temperature. When omitted, the router applies the model vendor's reference value, where one is configured.
top_pdoubleOptional
Nucleus sampling probability. When omitted, the router applies the model vendor's reference value, where one is configured.
reasoning_effortstringOptional
How much reasoning the model applies, for models that support it. When omitted, the router applies the model vendor's reference value, where one is configured.
max_tokensintegerOptional

Maximum tokens to generate. Per-model limits are published as max_tokens in GET /v1/models.

max_completion_tokensintegerOptional
Upper bound on generated tokens, including reasoning tokens.
stopstring or list of stringsOptional
Sequences where the model stops generating.
seedintegerOptional

A seed for best-effort deterministic sampling.

frequency_penaltydoubleOptional
Penalty for tokens by their frequency so far.
presence_penaltydoubleOptional
Penalty for tokens that have already appeared.
logit_biasmap from strings to doublesOptional
Token ID to bias value.
logprobsbooleanOptional
Return log probabilities of output tokens.
top_logprobsintegerOptional
Number of most likely tokens to return at each position.
nintegerOptional
Number of completions to generate.
response_formatmap from strings to anyOptional

Output format, such as {"type": "json_object"} or a json_schema definition.

toolslist of objectsOptional

Tools the model may call. Use function tools that your code executes, or the You.com web tools described below.

tool_choicestring or map from strings to anyOptional

Controls which tool the model calls: none, auto, required, or an object naming a function.

parallel_tool_callsbooleanOptional

Allow the model to call several tools in one turn. Defaults to true when a web tool is declared.

userstringOptional
A stable identifier for your end user.
metadatamap from strings to stringsOptional

Key-value pairs attached to the request.

Response headers

x-request-idstringOptional
The request ID, echoed from the request or generated by the router.
x-ydc-inference-response-duration-msdoubleOptional
Total time from the start of request processing to the response, in milliseconds.
x-ydc-inference-timing-llm-api-msdoubleOptional
Time spent waiting for the model, in milliseconds.
x-ydc-inference-timing-pre-processing-msdoubleOptional
Time for authentication, routing, and request work before the model call, in milliseconds.
x-ydc-inference-timing-post-processing-msdoubleOptional
Time to transform the response after the model call, in milliseconds.

Response

A chat completion, or a stream of chat.completion.chunk server-sent events when stream is true.

idstringOptional
objectenumOptional
Allowed values:
createdintegerOptional
modelstringOptional
choiceslist of objectsOptional
usageobjectOptional

Token counts, the same in streamed and non-streamed responses. The object has no cost fields.

web_resultsobjectOptional
Every search and page fetch the router ran for the request. Present only when a web tool ran. Citation numbers are shared across searches and extractions.

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
429
Too Many Requests Error
503
Service Unavailable Error