@xlaunch/llm-anthropic
v0.3.0-beta.4
Published
The native Anthropic Messages LLM adapter: the anthropic-messages wire protocol to one Anthropic-compatible endpoint, behind the Xlaunch LLM seam
Readme
description: "The native Anthropic Messages LLM adapter: the anthropic-messages wire protocol to one Anthropic-compatible endpoint, behind the Xlaunch LLM seam." kind: "package-reference"
@xlaunch/llm-anthropic
Summary
xlaunch-llm-anthropic carries the harness's anthropic-messages wire protocol: request serialization (system slot, tool calls, images), server-sent-event stream translation (text, thinking, and tool-use blocks; stop reasons; usage), and refusal mapping, plus AnthropicAdapter, a full LLM adapter any composition can register routes with. The gateway adapter serves routes that declare api: anthropic-messages through the same translation, so a route can point directly at an Anthropic-compatible endpoint without an OpenAI-compatible shim. Wire facts — the 2023-06-01 version header, event vocabulary, disjoint usage accounting, and image limits — are pinned to the Messages API reference.
Table of Contents
Use this package
Declare a route under llm-gateway.providers in $XLAUNCH_HOME/settings.yaml with api: anthropic-messages, an endpoint base address ending at the version segment, and a credential reference; the Models page offers the protocol because the gateway's route schema enumerates it:
llm-gateway:
providers:
claude-direct:
api: anthropic-messages
displayName: Claude (direct)
baseURL: https://api.anthropic.com/v1
apiKeyEnv: ANTHROPIC_API_KEY
models:
- id: claude-sonnet-4-5
contextWindow: 200000
maxTokens: 8192Compositions that register adapters themselves can construct AnthropicAdapter with the same dependency shape the gateway adapter takes — a route resolver, a credential resolver, and the attachment store — and register it with ctx.llm.registerAdapter(). The package is a library, not a plugin: it owns no settings section, and routes are declared where the gateway owns them.
Model Experience
Anthropic Messages dispatch
What the model sees
The adapter changes no model-visible text: it projects the assembled harness request onto the Messages wire — the system prompt and system-role history into the top-level system field, tool results into tool_result blocks inside user turns, assistant tool calls into tool_use blocks, and images into inline base64 sources read under the shared request-image policy — and streams response blocks back into harness chunks. A tool result's images ride the tool_result content array the API accepts beside its text, instead of being dropped from the string form. Stored tool-call arguments are re-parsed into tool_use input objects, and a stored call whose arguments do not parse is refused rather than rewritten.
Token effect
None of the request's tokens are added or removed here; the assembled request reaches the endpoint verbatim up to wire encoding. Anthropic reports disjoint counts (input_tokens excludes cached tokens), so usage maps directly: cache_read_input_tokens and cache_creation_input_tokens become the harness cache fields, and the total is derived from the authoritative parts.
KV Cache effect
Dispatch does not rewrite request prefixes, so an unchanged conversation prefix stays byte-stable across requests to the same route: consecutive same-role turns are sent as-is for the endpoint to combine, and system-role history folds deterministically. Changing the route's baseURL, credential, or model id in settings directs later requests to a different endpoint and forfeits that provider's cache reuse.
Known Limitations and Deferred Work
These limits define when this adapter is a poor fit. They are current package constraints, not a task backlog.
- No reasoning-effort mapping — the Messages API request carries no effort field, so routes served through this wire declare no reasoning efforts and an effort-bearing request is refused before dispatch. Extended thinking is never enabled on requests, while
thinkingblocks a gateway-enabled endpoint streams back are still translated into harness reasoning chunks. - No model discovery — model interrogation on the gateway's settings namespace speaks the OpenAI listing shape; an Anthropic endpoint answers it with model ids but not display names.
- Text and image output only — assistant-side image generation is not mapped; responses carry text, thinking, and tool-use blocks.
Dev Note
Runtime invariant: No companion is published. The wire translation is exercised directly by behavior specs (tests/stream.spec.ts, tests/request.spec.ts) against recorded server-sent-event transcripts; the adapter owns no durable package-local event stream.
