Skip to main content
Connect an OpenAI-compatible Chat Completions endpoint when you create or update an agent. Your endpoint generates the agent’s responses. Cartesia still runs speech recognition, speech synthesis, turn-taking, and tools.
To switch an existing agent, send the same model object in an agent update. Set url to your API’s base URL: https://llm.example.com/v1 receives requests at https://llm.example.com/v1/chat/completions. Your server must be reachable over public HTTPS.

Request and response format

Cartesia sends streaming POST requests with the agent’s instructions and conversation history:
Retries of a response reuse its Idempotency-Key request header. Speculative generation is on by default: Cartesia can start a request before the caller finishes and discard the reply if they keep talking, so requests for one call can overlap. Set config.speculative_generation to false to disable it.

Stream the response

Return Content-Type: text/event-stream with Chat Completions chunks separated by a blank line, followed by data: [DONE]. For example:
Cartesia does not charge for tokens generated by your custom endpoint. Return an uncompressed response of at most 256 KiB, including SSE framing. Cartesia does not follow redirects. This integration uses Chat Completions; a Responses-only endpoint is not compatible.

Use tools

Your model must support function calling to use the agent’s tools, including system tools. Return calls in choices[0].delta.tool_calls, using the names and parameter schemas from the request’s tools array. Cartesia dispatches the calls and includes their results in subsequent LLM requests. A single conversation turn can therefore make several requests to your endpoint.

Authentication

Set config.model.custom_llm to one of these configurations:
Bearer and Basic authentication set the Authorization header. You can combine either with additional request_headers, but not with another Authorization header. For an endpoint without authentication, omit authentication.

Call context

Set config.model.custom_llm.send_call_context to true to include your custom and available system dynamic variables in every LLM request:
This defaults to false; enable it only if your endpoint accepts cartesia_extra_body. Variables in the agent’s instructions are substituted regardless of this setting.

Update the endpoint or credentials

Sending custom_llm in an agent update replaces the entire object: include every setting you want to keep. Omitting it preserves the existing configuration. This update changes the model while keeping its stored bearer token:
The { "type": "secret" } placeholder keeps the credential stored at that field. To rotate it, supply a new secret_value. To switch back, set model.id to a managed model ID.

Failures and fallback

If your endpoint and every fallback fail, or a failure comes after output starts, that reply stops and the call continues. Any chunk meets these deadlines, including reasoning-only and empty ones; SSE comments don’t. Once text or a tool call arrives, Cartesia stops retrying and falling back. Before text or a tool call arrives, Cartesia retries timeouts, dropped connections, DNS failures, 429 and 5xx responses, and streams that end without output. Each endpoint gets at most two attempts and each reply at most four, with fallback models tried before the retry. 400, 401, 403, 404, 413, and 422 responses are not retried. Custom LLMs have no fallback by default. To enable fallback, set config.model.fallback_strategy with up to three managed model IDs, tried in order: