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 streamingPOST 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
ReturnContent-Type: text/event-stream with Chat Completions chunks separated by a blank line, followed by data: [DONE]. For example:
Use tools
Your model must support function calling to use the agent’s tools, including system tools. Return calls inchoices[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
Setconfig.model.custom_llm to one of these configurations:
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
Setconfig.model.custom_llm.send_call_context to true to include your custom and available system dynamic variables in every LLM request:
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
Sendingcustom_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:
{ "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: