> For the complete documentation index, see [llms.txt](https://docs.nexos.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexos.ai/gateway-api/chat.md).

# Chat

Generate a response from conversation messages.

## Create chat completion

> Generate a response from conversation messages.\
> \
> Parameter support varies by model: requests are validated by the upstream provider,\
> and parameters a given model does not support (for example \`temperature\` values other\
> than the default, \`top\_p\`, \`stop\`, \`logprobs\`, \`logit\_bias\`, or the penalty parameters\
> on reasoning models) are rejected with a \`400\` error. \`stream\_options\` is only allowed\
> together with \`stream: true\`.<br>

```json
{"openapi":"3.0.0","info":{"title":"Nexos AI Public API Production","version":"1.0.0"},"tags":[{"name":"Chat","description":"Generate a response from conversation messages."}],"servers":[{"url":"https://api.nexos.ai"}],"security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer"},"apiKeyHeader":{"type":"apiKey","in":"header","name":"X-Api-Key","description":"Authenticate by sending your nexos API key in the `X-Api-Key` header (e.g. `X-Api-Key: nexos-...` for a user key or `X-Api-Key: nexos-team-...` for a team key). This is an alternative to the `Authorization: Bearer` scheme. If both `X-Nexos-Key` and `X-Api-Key` are sent, `X-Nexos-Key` takes precedence."}},"schemas":{"ChatCompletionsRequest":{"type":"object","properties":{"messages":{"description":"A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.\n","type":"array","minItems":1,"items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessage"}},"model":{"type":"string","description":"Model name, UUID, or agent UUID."},"store":{"type":"boolean","description":"Whether or not to store the output of this chat completion request\n"},"metadata":{"type":"object","description":"Developer-defined tags and values used for filtering completions\nin the dashboard.\n","additionalProperties":{"type":"string"}},"frequency_penalty":{"type":"number","default":0,"minimum":-2,"maximum":2,"description":"Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.\n"},"logit_bias":{"type":"object","additionalProperties":{"type":"integer"},"description":"Modify the likelihood of specified tokens appearing in the completion.\n\nAccepts a JSON object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.\n"},"logprobs":{"description":"Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the `content` of `message`.","type":"boolean"},"top_logprobs":{"description":"An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability. `logprobs` must be set to `true` if this parameter is used.","type":"integer","minimum":0,"maximum":20},"max_tokens":{"description":"The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.\n\nThis value is now deprecated in favor of `max_completion_tokens`, and is not compatible with o1 series models.\n","type":"integer","nullable":true,"deprecated":true},"max_completion_tokens":{"description":"An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.\n","type":"integer","nullable":true},"n":{"type":"integer","minimum":1,"maximum":128,"default":1,"description":"How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs."},"modalities":{"$ref":"#/components/schemas/ChatCompletionModalities"},"prediction":{"description":"Configuration for a Predicted Output,\nwhich can greatly improve response times when large parts of the model\nresponse are known ahead of time. This is most common when you are\nregenerating a file with only minor changes to most of the content.\n","oneOf":[{"$ref":"#/components/schemas/PredictionContent"}]},"audio":{"type":"object","description":"Parameters for audio output. Required when audio output is requested with\n`modalities: [\"audio\"]`.\n","required":["voice","format"],"properties":{"voice":{"type":"string","enum":["alloy","ash","ballad","coral","echo","sage","shimmer","verse"],"description":"The voice the model uses to respond. Supported voices are `alloy`,\n`ash`, `ballad`, `coral`, `echo`, `sage`, `shimmer`, and `verse`.\n"},"format":{"type":"string","enum":["wav","mp3","flac","opus","pcm16"],"description":"Specifies the output audio format. Must be one of `wav`, `mp3`, `flac`,\n`opus`, or `pcm16`.\n"}}},"presence_penalty":{"type":"number","default":0,"minimum":-2,"maximum":2,"description":"Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.\n"},"response_format":{"description":"An object specifying the format that the model must output. Compatible with GPT-4o, GPT-4o mini, GPT-4 Turbo and all GPT-3.5 Turbo models newer than `gpt-3.5-turbo-1106`.\n\nSetting to `{ \"type\": \"json_schema\", \"json_schema\": {...} }` enables Structured Outputs which ensures the model will match your supplied JSON schema.\n\nSetting to `{ \"type\": \"json_object\" }` enables JSON mode, which ensures the message the model generates is valid JSON.\n\n**Important:** when using JSON mode, you **must** also instruct the model to produce JSON yourself via a system or user message. Without this, the model may generate an unending stream of whitespace until the generation reaches the token limit, resulting in a long-running and seemingly \"stuck\" request. Also note that the message content may be partially cut off if `finish_reason=\"length\"`, which indicates the generation exceeded `max_tokens` or the conversation exceeded the max context length.\n","oneOf":[{"$ref":"#/components/schemas/ResponseFormatText"},{"$ref":"#/components/schemas/ResponseFormatJsonObject"},{"$ref":"#/components/schemas/ResponseFormatJsonSchema"}]},"seed":{"type":"integer","minimum":-9223372036854776000,"maximum":9223372036854776000,"description":"This feature is in Beta.\nIf specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.\nDeterminism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.\n"},"service_tier":{"description":"Specifies the processing type used for serving the request.\nIf set to 'default' or 'auto', then the request will be processed with the standard pricing and performance for the selected model.\nIf set to 'flex' or 'priority', then the request will be processed with the corresponding service tier.\nWhen not set, the default behavior is 'auto'.\nWhen 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.\n","type":"string","enum":["auto","default","flex","scale","priority"],"default":"auto"},"stop":{"description":"Up to 4 sequences where the API will stop generating further tokens.\n","oneOf":[{"type":"string"},{"type":"array","minItems":1,"maxItems":4,"items":{"type":"string"}}]},"stream":{"description":"If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format) as they become available, with the stream terminated by a `data: [DONE]` message. Chunks follow the OpenAI `chat.completion.chunk` format; the final chunk additionally carries `usage` (with `nexos_credits_cost`), and some providers include a nexos `latency_checkpoint` object with detailed timing metrics. Note: Gemini-backed streams currently end without the `data: [DONE]` terminator.\n","type":"boolean"},"stream_options":{"$ref":"#/components/schemas/ChatCompletionStreamOptions"},"temperature":{"type":"number","minimum":0,"maximum":2,"default":1,"description":"What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.\n\nWe generally recommend altering this or `top_p` but not both.\n"},"top_p":{"type":"number","minimum":0,"maximum":1,"default":1,"description":"An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.\n\nWe generally recommend altering this or `temperature` but not both.\n"},"tools":{"type":"array","description":"A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.\n","items":{"$ref":"#/components/schemas/ChatCompletionTool"}},"tool_choice":{"$ref":"#/components/schemas/ChatCompletionToolChoiceOption"},"parallel_tool_calls":{"$ref":"#/components/schemas/ParallelToolCalls"},"function_call":{"deprecated":true,"description":"Deprecated in favor of `tool_choice`.\n\nControls which (if any) function is called by the model.\n`none` means the model will not call a function and instead generates a message.\n`auto` means the model can pick between generating a message or calling a function.\nSpecifying a particular function via `{\"name\": \"my_function\"}` forces the model to call that function.\n\n`none` is the default when no functions are present. `auto` is the default if functions are present.\n","oneOf":[{"type":"string","description":"`none` means the model will not call a function and instead generates a message. `auto` means the model can pick between generating a message or calling a function.\n","enum":["none","auto"]},{"$ref":"#/components/schemas/ChatCompletionFunctionCallOption"}]},"functions":{"deprecated":true,"description":"Deprecated in favor of `tools`.\n\nA list of functions the model may generate JSON inputs for.\n","type":"array","minItems":1,"maxItems":128,"items":{"$ref":"#/components/schemas/ChatCompletionFunctions"}},"thinking":{"type":"object","properties":{"type":{"type":"string","description":"The type of thinking configuration"},"budget_tokens":{"type":"integer","description":"The token budget allocation for thinking operations"}}},"reasoning_effort":{"type":"string","description":"Reasoning effort for models that support reasoning.","enum":["none","minimal","low","medium","high","xhigh","max"]},"verbosity":{"type":"string","description":"Constrains the verbosity of the model's response.","enum":["low","medium","high"]}},"required":["model","messages"]},"chat_completions_messages_ChatCompletionRequestMessage":{"oneOf":[{"$ref":"#/components/schemas/ChatCompletionRequestDeveloperMessage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestSystemMessage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestUserMessage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestAssistantMessage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestToolMessage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestFunctionMessage"}]},"ChatCompletionRequestDeveloperMessage":{"type":"object","title":"Developer message","description":"Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, `developer` messages\nreplace the previous `system` messages.\n","properties":{"content":{"description":"The contents of the developer message.","oneOf":[{"type":"string","description":"The contents of the developer message.","title":"Text content"},{"type":"array","description":"An array of content parts with a defined type. For developer messages, only type `text` is supported.","title":"Array of content parts","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartText"},"minItems":1}]},"role":{"type":"string","enum":["developer"],"description":"The role of the messages author, in this case `developer`."},"name":{"type":"string","description":"An optional name for the participant. Provides the model information to differentiate between participants of the same role."}},"required":["content","role"]},"chat_completions_messages_ChatCompletionRequestMessageContentPartText":{"type":"object","title":"Text content part","description":"Learn about [text inputs](/docs/guides/text-generation).\n","properties":{"type":{"type":"string","enum":["text"],"description":"The type of the content part."},"text":{"type":"string","description":"The text content."}},"required":["type","text"]},"chat_completions_messages_ChatCompletionRequestSystemMessage":{"type":"object","title":"System message","description":"Developer-provided instructions that the model should follow, regardless of\nmessages sent by the user. With o1 models and newer, use `developer` messages\nfor this purpose instead.\n","properties":{"content":{"description":"The contents of the system message.","oneOf":[{"type":"string","description":"The contents of the system message.","title":"Text content"},{"type":"array","description":"An array of content parts with a defined type. For system messages, only type `text` is supported.","title":"Array of content parts","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestSystemMessageContentPart"},"minItems":1}]},"role":{"type":"string","enum":["system"],"description":"The role of the messages author, in this case `system`."},"name":{"type":"string","description":"An optional name for the participant. Provides the model information to differentiate between participants of the same role."}},"required":["content","role"]},"chat_completions_messages_ChatCompletionRequestSystemMessageContentPart":{"oneOf":[{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartText"}]},"chat_completions_messages_ChatCompletionRequestUserMessage":{"type":"object","title":"User message","description":"Messages sent by an end user, containing prompts or additional context\ninformation.\n","properties":{"content":{"description":"The contents of the user message.\n","oneOf":[{"type":"string","description":"The text contents of the message.","title":"Text content"},{"type":"array","description":"An array of content parts with a defined type. Supported options differ based on the [model](/docs/models) being used to generate the response. Can contain text, image, or audio inputs.","title":"Array of content parts","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestUserMessageContentPart"},"minItems":1}]},"role":{"type":"string","enum":["user"],"description":"The role of the messages author, in this case `user`."},"name":{"type":"string","description":"An optional name for the participant. Provides the model information to differentiate between participants of the same role."}},"required":["content","role"]},"chat_completions_messages_ChatCompletionRequestUserMessageContentPart":{"oneOf":[{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartText"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartImage"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartAudio"}]},"chat_completions_messages_ChatCompletionRequestMessageContentPartImage":{"type":"object","title":"Image content part","description":"Learn about [image inputs](/docs/guides/vision).\n","properties":{"type":{"type":"string","enum":["image_url"],"description":"The type of the content part."},"image_url":{"type":"object","properties":{"url":{"type":"string","description":"Either a URL of the image or the base64 encoded image data.","format":"uri"},"detail":{"type":"string","description":"Specifies the detail level of the image. Learn more in the [Vision guide](/docs/guides/vision#low-or-high-fidelity-image-understanding).","enum":["auto","low","high"],"default":"auto"}},"required":["url"]}},"required":["type","image_url"]},"chat_completions_messages_ChatCompletionRequestMessageContentPartAudio":{"type":"object","title":"Audio content part","description":"Learn about [audio inputs](/docs/guides/audio).\n","properties":{"type":{"type":"string","enum":["input_audio"],"description":"The type of the content part. Always `input_audio`."},"input_audio":{"type":"object","properties":{"data":{"type":"string","description":"Base64 encoded audio data."},"format":{"type":"string","enum":["wav","mp3"],"description":"The format of the encoded audio data. Currently supports \"wav\" and \"mp3\".\n"}},"required":["data","format"]}},"required":["type","input_audio"]},"chat_completions_messages_ChatCompletionRequestAssistantMessage":{"type":"object","title":"Assistant message","description":"Messages sent by the model in response to user messages.\n","properties":{"content":{"nullable":true,"oneOf":[{"type":"string","description":"The contents of the assistant message.","title":"Text content"},{"type":"array","description":"An array of content parts with a defined type. Can be one or more of type `text`, or exactly one of type `refusal`.","title":"Array of content parts","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestAssistantMessageContentPart"},"minItems":1}],"description":"The contents of the assistant message. Required unless `tool_calls` or `function_call` is specified.\n"},"refusal":{"nullable":true,"type":"string","description":"The refusal message by the assistant."},"role":{"type":"string","enum":["assistant"],"description":"The role of the messages author, in this case `assistant`."},"name":{"type":"string","description":"An optional name for the participant. Provides the model information to differentiate between participants of the same role."},"audio":{"type":"object","nullable":true,"description":"Data about a previous audio response from the model. \n[Learn more](/docs/guides/audio).\n","required":["id"],"properties":{"id":{"type":"string","description":"Unique identifier for a previous audio response from the model.\n"}}},"tool_calls":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionMessageToolCalls"},"function_call":{"type":"object","deprecated":true,"description":"Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.","nullable":true,"properties":{"arguments":{"type":"string","description":"The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."},"name":{"type":"string","description":"The name of the function to call."}},"required":["arguments","name"]}},"required":["role"]},"chat_completions_messages_ChatCompletionRequestAssistantMessageContentPart":{"oneOf":[{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartText"},{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartRefusal"}]},"chat_completions_messages_ChatCompletionRequestMessageContentPartRefusal":{"type":"object","title":"Refusal content part","properties":{"type":{"type":"string","enum":["refusal"],"description":"The type of the content part."},"refusal":{"type":"string","description":"The refusal message generated by the model."}},"required":["type","refusal"]},"chat_completions_messages_ChatCompletionMessageToolCalls":{"type":"array","description":"The tool calls generated by the model, such as function calls.","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionMessageToolCall"}},"chat_completions_messages_ChatCompletionMessageToolCall":{"type":"object","properties":{"id":{"type":"string","description":"The ID of the tool call."},"type":{"type":"string","enum":["function"],"description":"The type of the tool. Currently, only `function` is supported."},"function":{"type":"object","description":"The function that the model called.","properties":{"name":{"type":"string","description":"The name of the function to call."},"arguments":{"type":"string","description":"The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."}},"required":["name","arguments"]}},"required":["id","type","function"]},"chat_completions_messages_ChatCompletionRequestToolMessage":{"type":"object","title":"Tool message","properties":{"role":{"type":"string","enum":["tool"],"description":"The role of the messages author, in this case `tool`."},"content":{"oneOf":[{"type":"string","description":"The contents of the tool message.","title":"Text content"},{"type":"array","description":"An array of content parts with a defined type. For tool messages, only type `text` is supported.","title":"Array of content parts","items":{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestToolMessageContentPart"},"minItems":1}],"description":"The contents of the tool message."},"tool_call_id":{"type":"string","description":"Tool call that this message is responding to."}},"required":["role","content","tool_call_id"]},"chat_completions_messages_ChatCompletionRequestToolMessageContentPart":{"oneOf":[{"$ref":"#/components/schemas/chat_completions_messages_ChatCompletionRequestMessageContentPartText"}]},"chat_completions_messages_ChatCompletionRequestFunctionMessage":{"type":"object","title":"Function message","deprecated":true,"properties":{"role":{"type":"string","enum":["function"],"description":"The role of the messages author, in this case `function`."},"content":{"nullable":true,"type":"string","description":"The contents of the function message."},"name":{"type":"string","description":"The name of the function to call."}},"required":["role","content","name"]},"ChatCompletionModalities":{"type":"array","description":"Output types that you would like the model to generate for this request.\nMost models are capable of generating text, which is the default:\n\n`[\"text\"]`\n\nTo request that this model generate both text and audio responses, you can use:\n\n`[\"text\", \"audio\"]`\n","items":{"type":"string","enum":["text","audio"]}},"PredictionContent":{"type":"object","title":"Static Content","description":"Static predicted output content, such as the content of a text file that is being regenerated.\n","required":["type","content"],"properties":{"type":{"type":"string","enum":["content"],"description":"The type of the predicted content you want to provide. This type is\ncurrently always `content`.\n"},"content":{"description":"The content that should be matched when generating a model response.\nIf generated tokens would match this content, the entire model response\ncan be returned much more quickly.\n","oneOf":[{"type":"string","title":"Text content","description":"The content used for a Predicted Output. This is often the\ntext of a file you are regenerating with minor changes.\n"},{"type":"array","description":"An array of content parts with a defined type. Supported options differ based on the [model](/docs/models) being used to generate the response. Can contain text inputs.","title":"Array of content parts","items":{"$ref":"#/components/schemas/ChatCompletionRequestMessageContentPartText"},"minItems":1}]}}},"ChatCompletionRequestMessageContentPartText":{"type":"object","title":"Text content part","properties":{"type":{"type":"string","enum":["text"],"description":"The type of the content part."},"text":{"type":"string","description":"The text content."}},"required":["type","text"]},"ResponseFormatText":{"type":"object","properties":{"type":{"type":"string","description":"The type of response format being defined: `text`","enum":["text"]}},"required":["type"]},"ResponseFormatJsonObject":{"type":"object","properties":{"type":{"type":"string","description":"The type of response format being defined: `json_object`","enum":["json_object"]}},"required":["type"]},"ResponseFormatJsonSchema":{"type":"object","properties":{"type":{"type":"string","description":"The type of response format being defined: `json_schema`","enum":["json_schema"]},"json_schema":{"type":"object","properties":{"description":{"type":"string","description":"A description of what the response format is for, used by the model to determine how to respond in the format."},"name":{"type":"string","description":"The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64."},"schema":{"$ref":"#/components/schemas/ResponseFormatJsonSchemaSchema"},"strict":{"type":"boolean","nullable":true,"default":false,"description":"Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the `schema` field. Only a subset of JSON Schema is supported when `strict` is `true`. To learn more, read the [Structured Outputs guide](/docs/guides/structured-outputs)."}},"required":["type","name"]}},"required":["type","json_schema"]},"ResponseFormatJsonSchemaSchema":{"type":"object","description":"The schema for the response format, described as a JSON Schema object.","additionalProperties":true},"ChatCompletionStreamOptions":{"description":"Options for streaming response. Only set this when you set `stream: true`.\n","type":"object","properties":{"include_usage":{"type":"boolean","description":"If set, an additional chunk will be streamed before the `data: [DONE]` message. The `usage` field on this chunk shows the token usage statistics for the entire request, and the `choices` field will always be an empty array. All other chunks will also include a `usage` field, but with a null value\n"}}},"ChatCompletionTool":{"type":"object","properties":{"type":{"type":"string","enum":["function","web_search","rag","tika_ocr"],"description":"The type of the tool. Supports `function`, `web_search`, `rag` and `tika_ocr`."},"function":{"$ref":"#/components/schemas/FunctionObject"},"web_search":{"$ref":"#/components/schemas/ChatCompletionWebSearch"},"rag":{"$ref":"#/components/schemas/ChatCompletionRAG"},"tika_ocr":{"$ref":"#/components/schemas/ChatCompletionTikaOCR"}},"required":["type"]},"FunctionObject":{"type":"object","properties":{"description":{"type":"string","description":"A description of what the function does, used by the model to choose when and how to call the function."},"name":{"type":"string","description":"The 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."},"parameters":{"$ref":"#/components/schemas/FunctionParameters"},"strict":{"type":"boolean","nullable":true,"default":false,"description":"Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the `parameters` field. Only a subset of JSON Schema is supported when `strict` is `true`."}},"required":["name"]},"FunctionParameters":{"type":"object","description":"The parameters the functions accepts, described as a JSON Schema object.\nOmitting `parameters` defines a function with an empty parameter list.","additionalProperties":true},"ChatCompletionWebSearch":{"type":"object","description":"The web search that the model called.","properties":{"search_context_size":{"type":"string","description":"High level guidance for the amount of context window space to use for the search.","enum":["low","medium","high"]},"user_location":{"$ref":"#/components/schemas/UserLocation"},"mcp":{"$ref":"#/components/schemas/WebSearchMCP"}}},"UserLocation":{"type":"object","required":["type"],"properties":{"type":{"type":"string","description":"The type of location approximation.","enum":["approximate"]},"city":{"type":"string","description":"The city to use for the location approximation."},"country":{"type":"string","description":"The two-letter ISO country code of the user."},"region":{"type":"string","description":"Free text input for the region of the user."},"timezone":{"type":"string","description":"The IANA timezone of the user."}}},"WebSearchMCP":{"type":"object","description":"Custom MCP web_search","required":["type","options`"],"properties":{"type":{"type":"string","description":"The type of the web search.","enum":["url","query"]},"options":{"oneOf":[{"$ref":"#/components/schemas/QuerySearch"},{"$ref":"#/components/schemas/URLSearch"}]}}},"QuerySearch":{"type":"object","required":["tool","query"],"properties":{"tool":{"type":"string","description":"The type of tool used for web search.","enum":["google_search","bing_search","amazon_search"]},"query":{"type":"string","description":"The query to search for."},"geo_location":{"type":"string","description":"The geographic location to use for the search."},"parse":{"type":"boolean","description":"Whether to parse the search results.","default":false}}},"URLSearch":{"type":"object","required":["tool","url"],"properties":{"tool":{"type":"string","description":"The type of the web search.","enum":["universal"]},"url":{"type":"string","description":"The URL to search for."},"geo_location":{"type":"string","description":"The geographic location to use for the search."},"parse":{"type":"boolean","description":"Whether to parse the search results.","default":false}}},"ChatCompletionRAG":{"type":"object","description":"RAG tool call","properties":{"mcp":{"$ref":"#/components/schemas/RagMCP"}}},"RagMCP":{"type":"object","description":"RAG MCP tool call","required":["collection_uuid"],"properties":{"collection_uuid":{"type":"string","description":"The UUID of the collection to search."},"query":{"type":"string","description":"The query to search for."},"threshold":{"type":"number","format":"float","description":"The threshold for the search results."},"top_n":{"type":"integer","description":"The number of top results to return."},"model_uuid":{"type":"string","description":"The UUID of the model to use for the search."}}},"ChatCompletionTikaOCR":{"type":"object","description":"Tika OCR that the model called.","properties":{"file_id":{"type":"string"}},"required":["file_id"]},"ChatCompletionToolChoiceOption":{"description":"Controls which (if any) tool is called by the model.\n`none` means the model will not call any tool and instead generates a message.\n`auto` means the model can pick between generating a message or calling one or more tools.\n`required` means the model must call one or more tools.\nSpecifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.\n\n`none` is the default when no tools are present. `auto` is the default if tools are present.\n","oneOf":[{"type":"string","description":"`none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools.\n","enum":["none","auto","required"]},{"$ref":"#/components/schemas/ChatCompletionNamedToolChoice"}]},"ChatCompletionNamedToolChoice":{"type":"object","description":"Specifies a tool the model should use. Use to force the model to call a specific function.","properties":{"type":{"type":"string","enum":["function"],"description":"The type of the tool. Currently, only `function` is supported."},"function":{"type":"object","properties":{"name":{"type":"string","description":"The name of the function to call."}},"required":["name"]}},"required":["type","function"]},"ParallelToolCalls":{"description":"Whether to enable parallel function calling during tool use.","type":"boolean","default":true},"ChatCompletionFunctionCallOption":{"type":"object","description":"Specifying a particular function via `{\"name\": \"my_function\"}` forces the model to call that function.\n","properties":{"name":{"type":"string","description":"The name of the function to call."}},"required":["name"]},"ChatCompletionFunctions":{"type":"object","properties":{"description":{"type":"string","description":"A description of what the function does, used by the model to choose when and how to call the function."},"name":{"type":"string","description":"The 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."},"parameters":{"$ref":"#/components/schemas/FunctionParameters"}},"required":["name"]},"ChatCompletionFinishReason":{"type":"string","description":"The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence,\n`length` if the maximum number of tokens specified in the request was reached,\n`content_filter` if content was omitted due to a flag from our content filters,\n`tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.\n\nWhen extended thinking is requested (`thinking` parameter) for an Anthropic-backed model, the response is returned in Anthropic-native form and this field carries Anthropic stop reasons instead: `end_turn`, `max_tokens`, `stop_sequence`, `tool_use`, `pause_turn`, or `refusal`. Without `thinking`, Anthropic-backed responses are translated to the standard values above.\n","enum":["stop","length","tool_calls","content_filter","function_call","end_turn","max_tokens","stop_sequence","tool_use","pause_turn","refusal"]},"ChatCompletionResponseMessage":{"type":"object","description":"A chat completion message generated by the model.","properties":{"content":{"description":"The contents of the message. When extended thinking is requested (`thinking` parameter) for an Anthropic-backed model, this is an array of Anthropic-native content blocks (`thinking` and `text`) instead of a string, since thinking blocks cannot be represented in the standard shape.\n","oneOf":[{"type":"string","nullable":true,"title":"Text content","description":"The contents of the message."},{"type":"array","title":"Anthropic-native content blocks","description":"Returned when extended thinking is requested for an Anthropic-backed model, e.g. `{\"type\": \"thinking\", \"thinking\": \"...\"}` followed by `{\"type\": \"text\", \"text\": \"...\"}`.\n","items":{"type":"object"}}]},"refusal":{"type":"string","description":"The refusal message generated by the model.","nullable":true},"tool_calls":{"$ref":"#/components/schemas/ChatCompletionMessageToolCalls"},"role":{"type":"string","enum":["assistant"],"description":"The role of the author of this message."},"function_call":{"type":"object","deprecated":true,"description":"Deprecated and replaced by `tool_calls`. The name and arguments of a function that should be called, as generated by the model.","properties":{"arguments":{"type":"string","description":"The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."},"name":{"type":"string","description":"The name of the function to call."}},"required":["name","arguments"]},"audio":{"type":"object","nullable":true,"description":"If the audio output modality is requested, this object contains data\nabout the audio response from the model. [Learn more](/docs/guides/audio).\n","required":["id","expires_at","data","transcript"],"properties":{"id":{"type":"string","description":"Unique identifier for this audio response."},"expires_at":{"type":"integer","description":"The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.\n"},"data":{"type":"string","description":"Base64 encoded audio bytes generated by the model, in the format\nspecified in the request.\n"},"transcript":{"type":"string","description":"Transcript of the audio generated by the model."}}},"annotations":{"type":"array","description":"Annotations for the message, when applicable, as when using the web search tool.","items":{"$ref":"#/components/schemas/Annotation"}}},"required":["role","content","refusal"]},"ChatCompletionMessageToolCalls":{"type":"array","description":"The tool calls generated by the model, such as function calls.","items":{"$ref":"#/components/schemas/ChatCompletionMessageToolCall"}},"ChatCompletionMessageToolCall":{"type":"object","properties":{"id":{"type":"string","description":"The ID of the tool call."},"type":{"type":"string","enum":["function"],"description":"The type of the tool. Currently, only `function` is supported."},"function":{"type":"object","description":"The function that the model called.","properties":{"name":{"type":"string","description":"The name of the function to call."},"arguments":{"type":"string","description":"The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."}},"required":["name","arguments"]}},"required":["id","type","function"]},"Annotation":{"type":"object","properties":{"type":{"type":"string","description":"The type of the URL citation. Always url_citation."},"url_citation":{"$ref":"#/components/schemas/URLCitation"}}},"URLCitation":{"type":"object","description":"A URL citation when using web search.","properties":{"end_index":{"type":"integer","description":"The index of the last character of the URL citation in the message."},"start_index":{"type":"integer","description":"The index of the first character of the URL citation in the message."},"title":{"type":"string","description":"The title of the web resource."},"url":{"type":"string","description":"The URL of the web resource."}}},"ChatCompletionTokenLogprob":{"type":"object","properties":{"token":{"description":"The token.","type":"string"},"logprob":{"description":"The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely.\n","type":"number"},"bytes":{"description":"A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token.\n","type":"array","items":{"type":"integer"},"nullable":true},"top_logprobs":{"description":"List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested `top_logprobs` returned.\n","type":"array","items":{"type":"object","properties":{"token":{"description":"The token.","type":"string"},"logprob":{"description":"The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value `-9999.0` is used to signify that the token is very unlikely.\n","type":"number"},"bytes":{"description":"A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be `null` if there is no bytes representation for the token.\n","type":"array","items":{"type":"integer"},"nullable":true}},"required":["token","logprob","bytes"]}}},"required":["token","logprob","bytes","top_logprobs"]},"ChatCompletionServiceTier":{"description":"The service tier used for processing the request. This field is only included if the `service_tier` parameter is specified in the request. The value may differ from the `service_tier` parameter sent in the request. For example, if 'auto' is specified, the response will return 'default' as they are equivalent.\n","type":"string","enum":["auto","default","flex","scale","priority"],"nullable":true},"ChatCompletionObject":{"type":"string","description":"The object type, which is always `chat.completion`.","enum":["chat.completion"]},"CompletionUsage":{"type":"object","description":"Usage statistics for the completion request.","properties":{"completion_tokens":{"type":"integer","description":"Number of tokens in the generated completion."},"prompt_tokens":{"type":"integer","description":"Number of tokens in the prompt."},"total_tokens":{"type":"integer","description":"Total number of tokens used in the request (prompt + completion)."},"nexos_credits_cost":{"type":"number","format":"double","description":"Cost of the request in nexos credits."},"completion_tokens_details":{"type":"object","description":"Breakdown of tokens used in a completion.","properties":{"accepted_prediction_tokens":{"type":"integer","description":"When using Predicted Outputs, the number of tokens in the\nprediction that appeared in the completion.\n"},"audio_tokens":{"type":"integer","description":"Audio input tokens generated by the model."},"reasoning_tokens":{"type":"integer","description":"Tokens generated by the model for reasoning."},"rejected_prediction_tokens":{"type":"integer","description":"When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, output, and context window limits.\n"},"image_tokens":{"type":"integer","description":"Image output tokens generated by the model. Returned by some providers."}}},"prompt_tokens_details":{"type":"object","description":"Breakdown of tokens used in the prompt.","properties":{"audio_tokens":{"type":"integer","description":"Audio input tokens present in the prompt."},"cached_tokens":{"type":"integer","description":"Cached tokens present in the prompt."},"cache_write_tokens":{"type":"integer","description":"Tokens written to the prompt cache. Nexos extension."},"image_tokens":{"type":"integer","description":"Image input tokens present in the prompt. Returned by some providers."}}},"cache_creation_input_tokens":{"type":"integer","nullable":true,"description":"Input tokens stored into the prompt cache during this request. Returned for Anthropic-backed models (provider passthrough).\n"},"cache_read_input_tokens":{"type":"integer","nullable":true,"description":"Input tokens read back from the prompt cache. Returned for Anthropic-backed models (provider passthrough).\n"},"cache_creation":{"type":"object","nullable":true,"description":"Breakdown of cache-write tokens split by cache lifetime tier. Returned for Anthropic-backed models (provider passthrough).\n","properties":{"ephemeral_5m_input_tokens":{"type":"integer"},"ephemeral_1h_input_tokens":{"type":"integer"}}}},"required":["prompt_tokens","completion_tokens","total_tokens"]}},"responses":{"ChatCompletionsResponse":{"description":"Represents a chat completion response returned by model, based on the provided input.\n","headers":{"X-Nexos-Completion-Time-Ms":{"schema":{"type":"integer"},"description":"Time in milliseconds that server took for completion"},"X-Nexos-Model-Id":{"schema":{"type":"string"},"description":"Model ID that was user to perform the completion"}},"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","description":"A unique identifier for the chat completion."},"choices":{"type":"array","description":"A list of chat completion choices. Can be more than one if `n` is greater than 1.\n","items":{"type":"object","required":["finish_reason","index","message","logprobs"],"properties":{"finish_reason":{"$ref":"#/components/schemas/ChatCompletionFinishReason"},"index":{"type":"integer","description":"The index of the choice in the list of choices."},"message":{"$ref":"#/components/schemas/ChatCompletionResponseMessage"},"content_filter_results":{"type":"object","description":"Content-filter annotations for this choice, passed through from the upstream provider (returned by Azure-hosted models).\n"},"logprobs":{"description":"Log probability information for the choice.","type":"object","properties":{"content":{"description":"A list of message content tokens with log probability information.","type":"array","items":{"$ref":"#/components/schemas/ChatCompletionTokenLogprob"},"nullable":true},"refusal":{"description":"A list of message refusal tokens with log probability information.","type":"array","items":{"$ref":"#/components/schemas/ChatCompletionTokenLogprob"},"nullable":true}},"required":["content","refusal"]}}}},"created":{"type":"integer","description":"The Unix timestamp (in seconds) of when the chat completion was created."},"model":{"type":"string","description":"The model used for the chat completion."},"service_tier":{"$ref":"#/components/schemas/ChatCompletionServiceTier"},"system_fingerprint":{"type":"string","description":"This fingerprint represents the backend configuration that the model runs with.\n\nCan be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.\n"},"object":{"$ref":"#/components/schemas/ChatCompletionObject"},"usage":{"$ref":"#/components/schemas/CompletionUsage"},"provider":{"type":"string","description":"The upstream provider that served the request (e.g. `vertex-ai`). Returned for provider-passthrough responses.\n"},"prompt_filter_results":{"type":"array","description":"Prompt content-filter annotations passed through from the upstream provider (returned by Azure-hosted models).\n","items":{"type":"object","properties":{"prompt_index":{"type":"integer"},"content_filter_results":{"type":"object"}}}},"guardrails":{"type":"object","description":"Results of the guardrail checks. Present when guardrails are configured for the company.\n","properties":{"validation_passed":{"type":"boolean","description":"Whether all guardrail checks passed."},"reask":{"type":"string","nullable":true,"description":"Reask prompt suggested by a failed guardrail, if any."},"error":{"type":"string","nullable":true,"description":"Guardrail processing error, if any."},"results":{"type":"array","description":"Individual guardrail check results.","items":{"type":"object","properties":{"type":{"type":"string","description":"The guardrail type (e.g. `detect_pii`)."},"result":{"type":"string","description":"The check outcome (e.g. `pass`)."},"target":{"type":"string","description":"Which side of the exchange was checked (`input` or `output`)."}}}}}}},"required":["choices","created","id","model","object"]}}}},"OutOfCredits":{"description":"The company has run out of AI credits. Returned when the company's budget limit has been reached.\n","content":{"application/json":{"schema":{"type":"object","required":["error"],"properties":{"error":{"type":"object","required":["message"],"properties":{"message":{"type":"string"}}}}}}}}}},"paths":{"/v1/chat/completions":{"post":{"tags":["Chat"],"operationId":"post-chat-completions-v1","summary":"Create chat completion","description":"Generate a response from conversation messages.\n\nParameter support varies by model: requests are validated by the upstream provider,\nand parameters a given model does not support (for example `temperature` values other\nthan the default, `top_p`, `stop`, `logprobs`, `logit_bias`, or the penalty parameters\non reasoning models) are rejected with a `400` error. `stream_options` is only allowed\ntogether with `stream: true`.\n","parameters":[{"in":"query","name":"fallbacks","schema":{"type":"string","enum":["true","false"]},"required":false,"description":"To use or not fallbacks in chat completion request"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionsRequest"}}}},"responses":{"200":{"$ref":"#/components/responses/ChatCompletionsResponse"},"400":{"description":"Invalid request data."},"402":{"$ref":"#/components/responses/OutOfCredits"},"500":{"description":"Server error."}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nexos.ai/gateway-api/chat.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
