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).
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.anthropic.v1.messages({
max_tokens: 0,
messages: [],
model: 'model',
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.anthropic.v1.messages(
max_tokens=0,
messages=[],
model="model",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Anthropic.V1.Messages(
context.TODO(),
telnyx.AIAnthropicV1MessagesParams{
MaxTokens: 1,
Messages: "messages",
Model: "model",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.anthropic.v1.V1MessagesParams;
import java.util.List;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
V1MessagesParams params = V1MessagesParams.builder()
.maxTokens(0)
.messages(List.of())
.model("model")
.build();
var response = client.ai().anthropic().v1().messages(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.anthropic.v1.messages(max_tokens: 0, messages: [], model: "model")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->anthropic->v1->messages(
max_tokens: 0,
messages: [],
model: 'model',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:anthropic:v1 messages \
--api-key 'My API Key' \
--model model \
--messages messages \
--max-tokens 0curl --request POST \
--url https://api.telnyx.com/v2/ai/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "zai-org/GLM-5.3-Flash",
"system": "You are a friendly chatbot.",
"messages": [
{
"role": "user",
"content": "Hello, world!"
}
],
"max_tokens": 1024
}
'{
"id": "msg_01B8b1f2a3c9d4e5f6a",
"type": "message",
"role": "assistant",
"model": "zai-org/GLM-5.3-Flash",
"content": [
{
"type": "text",
"text": "Telnyx provides carrier-grade voice, messaging, and AI inference through one API."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 24,
"output_tokens": 18
}
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}Authorizations
Body
Anthropic Messages-compatible request with Telnyx extensions.
The messages to send to the model, following the Anthropic Messages API format.
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.
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.
USA, EU, AUS, UAE 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.
preferred, strict Response
Successful Response
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.
Was this page helpful?
import Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});
const response = await client.ai.anthropic.v1.messages({
max_tokens: 0,
messages: [],
model: 'model',
});
console.log(response.data);import os
from telnyx import Telnyx
client = Telnyx(
api_key=os.environ.get("TELNYX_API_KEY"), # This is the default and can be omitted
)
response = client.ai.anthropic.v1.messages(
max_tokens=0,
messages=[],
model="model",
)
print(response.data)
package main
import (
"context"
"fmt"
"github.com/team-telnyx/telnyx-go"
"github.com/team-telnyx/telnyx-go/option"
)
func main() {
client := telnyx.NewClient(
option.WithAPIKey("My API Key"),
)
response, err := client.AI.Anthropic.V1.Messages(
context.TODO(),
telnyx.AIAnthropicV1MessagesParams{
MaxTokens: 1,
Messages: "messages",
Model: "model",
},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;
import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.ai.anthropic.v1.V1MessagesParams;
import java.util.List;
public final class Main {
private Main() {}
public static void main(String[] args) {
TelnyxClient client = TelnyxOkHttpClient.fromEnv();
V1MessagesParams params = V1MessagesParams.builder()
.maxTokens(0)
.messages(List.of())
.model("model")
.build();
var response = client.ai().anthropic().v1().messages(params);
}
}require "telnyx"
telnyx = Telnyx::Client.new(api_key: "My API Key")
response = telnyx.ai.anthropic.v1.messages(max_tokens: 0, messages: [], model: "model")
puts(response)<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;
$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');
try {
$response = $client->ai->anthropic->v1->messages(
max_tokens: 0,
messages: [],
model: 'model',
);
var_dump($response);
} catch (APIException $e) {
echo $e->getMessage();
}telnyx ai:anthropic:v1 messages \
--api-key 'My API Key' \
--model model \
--messages messages \
--max-tokens 0curl --request POST \
--url https://api.telnyx.com/v2/ai/anthropic/v1/messages \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "zai-org/GLM-5.3-Flash",
"system": "You are a friendly chatbot.",
"messages": [
{
"role": "user",
"content": "Hello, world!"
}
],
"max_tokens": 1024
}
'{
"id": "msg_01B8b1f2a3c9d4e5f6a",
"type": "message",
"role": "assistant",
"model": "zai-org/GLM-5.3-Flash",
"content": [
{
"type": "text",
"text": "Telnyx provides carrier-grade voice, messaging, and AI inference through one API."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 24,
"output_tokens": 18
}
}{
"detail": [
{
"loc": [
"body",
"name"
],
"msg": "Field required",
"type": "missing"
}
]
}