Skip to content

AnthropicFrontendAdapter

Defined in: adapters/anthropic.ts:287

Frontend adapter for Anthropic Messages API.

new AnthropicFrontendAdapter(): AnthropicFrontendAdapter

AnthropicFrontendAdapter

readonly metadata: AdapterMetadata

Defined in: adapters/anthropic.ts:292

Adapter metadata for identification and capabilities.

FrontendAdapter.metadata

fromIR(response): Promise<AnthropicResponse>

Defined in: adapters/anthropic.ts:402

Convert Universal IR response back to Anthropic Messages API format.

This method transforms the standardized IR response into the format expected by Anthropic’s Messages API. It handles message conversion, stop reason mapping, and usage statistics formatting specific to Anthropic’s response structure.

IRChatResponse

Universal IR chat response

Promise<AnthropicResponse>

Promise resolving to Anthropic Messages API response

If conversion fails

const adapter = new AnthropicFrontendAdapter();
const anthropicResponse = await adapter.fromIR(irResponse);
console.log(anthropicResponse.content[0].text);

FrontendAdapter.fromIR


fromIRStream(stream, options?): AsyncGenerator<AnthropicStreamEvent, void, undefined>

Defined in: adapters/anthropic.ts:461

Convert Universal IR stream to Anthropic Server-Sent Events (SSE) format.

This async generator method transforms a stream of IR chunks into Anthropic-formatted streaming events. It handles stream mode conversion, tracks message metadata, and emits properly formatted SSE events compatible with Anthropic’s streaming API including message_start, content_block_delta, and message_stop events.

IRChatStream

Universal IR chat stream

StreamConversionOptions

Optional stream conversion options (stream mode, etc.)

AsyncGenerator<AnthropicStreamEvent, void, undefined>

Anthropic-formatted streaming events

If stream conversion fails

const adapter = new AnthropicFrontendAdapter();
for await (const event of adapter.fromIRStream(irStream)) {
if (event.type === 'content_block_delta') {
console.log(event.delta.text);
}
}

FrontendAdapter.fromIRStream


toIR(request): Promise<IRChatRequest>

Defined in: adapters/anthropic.ts:332

Convert Anthropic Messages API request to Universal IR format.

This method transforms an Anthropic-formatted request into the standardized Intermediate Representation (IR) format. It handles Anthropic’s unique system message format (separate from messages array) by converting it to IR’s in-messages format, and maps Anthropic-specific parameters like top_k.

AnthropicRequest

Anthropic Messages API request

Promise<IRChatRequest>

Promise resolving to IR chat request

If conversion fails

const adapter = new AnthropicFrontendAdapter();
const irRequest = await adapter.toIR({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }],
system: 'You are a helpful assistant'
});

FrontendAdapter.toIR