Anthropic Messages

Create a message (Anthropic-compatible)

Send a message to a language model using the Anthropic Messages API format. This endpoint is compatible with the Anthropic Messages API and may be used with the Anthropic JS or Python SDK by setting the base URL to https://api.telnyx.com/v2/ai/anthropic.

The endpoint translates Anthropic-format requests into Telnyx's inference internals, then translates the response back to the Anthropic message shape. Streaming responses use Anthropic SSE event types (message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop).

post/ai/anthropic/v1/messages

Request body

modelstring required

The model to use for generating the response, for example zai-org/GLM-5.3-Flash or another model available from the Telnyx models endpoint.

messagesobject[] required

The messages to send to the model, following the Anthropic Messages API format.

max_tokensinteger required

The maximum number of tokens to generate in the response.

streamboolean

Whether to stream the response as Anthropic-format Server-Sent Events.

temperaturenumber

Amount of randomness injected into the response. Ranges from 0 to 1.

top_pnumber

Nucleus sampling parameter. Use temperature or top_p, but not both.

top_kinteger

Top-k sampling parameter. Only sample from the top K options for each subsequent token.

stop_sequencesstring[]

Custom sequences that will cause the model to stop generating.

metadataobject

An object describing metadata about the request.

toolsobject[]

Definitions of tools that the model may use, following the Anthropic API format.

tool_choiceobject

Controls how the model uses tools, following the Anthropic API format.

thinkingobject

Extended thinking configuration for models that support it. Set type to enabled to turn on extended thinking.

api_key_refstring

If you are using an external inference provider, this field allows you to pass along a reference to your API key. After creating an integration secret for your API key, pass the secret's identifier in this field.

mcp_serversobject[]

List of MCP (Model Context Protocol) servers to make available to the model.

fallback_configobject

Configuration for model fallback behavior when the primary model is unavailable.

billing_group_idstring uuid

The billing group ID to associate with this request.

timeoutnumber

Request timeout in seconds.

max_retriesinteger

Maximum number of retries for the request.

service_tierstring

The service tier to use for this request. Supported values vary by model; use the Telnyx models endpoint and inspect the model's service_tiers field. If omitted, Telnyx-hosted models use default.

region'USA' | 'EU' | 'AUS' | 'UAE'

Optional data-residency region the request should be served from, using the same vocabulary as your account's Data Locality setting. Behavior depends on mode. Supported for Telnyx-hosted models only: a request routed to an external provider never passes through Telnyx model routing, so a region cannot be enforced for it. Omit for today's latency-based routing.

mode'preferred' | 'strict'

How strictly region is applied. preferred (the default when region is set) tries that region first and falls back to another when the model cannot be served there, so a request that would have succeeded still succeeds. strict pins the request: it is served from that region or it fails with a 422, never redirected to another region. Requires region.

Response

Successful Response

object required

An Anthropic-format message response with type: "message", role, content, stop_reason, stop_sequence, and usage. When stream is true, the response is a text/event-stream of Anthropic SSE events.

Changes

Changed in 3 of the 99 revisions of this API.13

Of the 99 revisions, 1 has no diff computed.