Messages API
Use a normalized Messages-shaped API across native and compatible providers.
messages() accepts Messages-style content blocks, tools, thinking controls, and stream events.
Anthropic-family adapters use their native Messages protocol. Other compatible providers translate
the request through chat completions and translate the result back into MessageResponse.
metadata.messagesNative is true for providers that can call a real Anthropic Messages endpoint
(anthropic, azureanthropic, vertexaianthropic, bedrock, meta, and otari). Bedrock
serves only Claude model ids natively (anthropic. in the id, including cross-region and
inference-profile forms). Use AnyLLM.servesMessagesNatively(provider, model) when the answer
depends on the model. Other Bedrock models, and Claude requests with outputFormat, still use
the Completions bridge. On the native Claude path, Bedrock keeps only the betas AWS documents,
moves a top-level cacheControl onto the last cacheable block, adds
thinking-display-updates-2026-08-18 when thinking.display is "updates", and refuses
container. Native Anthropic and Meta calls strip the Messages bridge extraContent side-channel
and render another provider's code-execution blocks as text, so a conversation that switches from
Gemini to Claude does not send fields or ids Anthropic never issued. Gemini and Vertex AI read
cacheControl breakpoints from that side-channel; other compatibility providers do not.
import { messages } from "any-llm-ts";
const response = await messages({
provider: "anthropic",
model: "claude-sonnet-4-5",
maxTokens: 512,
system: "Be concise.",
messages: [{ role: "user", content: "Explain mapped types." }],
});
for (const block of response.content) {
if (block.type === "text") console.log(block.text);
}Messages calls also accept a per-request timeout in seconds and a provider serviceTier. Native
Anthropic-family adapters forward both directly; compatibility adapters map them through chat
completions. Anthropic and Otari also accept inferenceGeo (Anthropic's region, such as us);
other providers raise UnsupportedParameterError. Completions report the region on
usage.inferenceGeo and the billed serviceTier when Anthropic sends them. Native Anthropic-family adapters also accept container so a later turn can continue
a previous top-level code-execution container. Compatibility adapters, Meta, and Otari reject
container. When returned by the provider, requestId is normalized on MessageResponse.
Tools
const response = await llm.messages({
model,
maxTokens: 512,
messages: [{ role: "user", content: "Look up order 123." }],
tools: [
{
name: "get_order",
description: "Retrieve an order",
inputSchema: {
type: "object",
properties: { id: { type: "string" } },
required: ["id"],
},
},
],
toolChoice: { type: "auto" },
});Tool uses and results are normalized as tool_use and tool_result blocks. Providers may preserve
signatures and other native fields in their content blocks.
Streaming
const events = await llm.messages({
model,
maxTokens: 512,
messages: [{ role: "user", content: "Count to five." }],
stream: true,
});
for await (const event of events) {
if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}Compatibility streams emit the standard message-start, content-block, message-delta, and message-stop lifecycle. Native-only beta and context-management options reject on adapters that cannot preserve their semantics.
A typed outputFormat (one with parse) still cannot stream except on Anthropic and Otari,
because parsing needs a finished message. A raw output_config dict streams as JSON text through
the Completions bridge, with its schema sent as responseFormat. Providers that cannot stream a
responseFormat still refuse at the completion layer. Meta's native Messages path refuses any
outputFormat combined with stream.