Skip to content
Français

createAnthropicModelProvider

import { createAnthropicModelProvider } from "@elie-laloum/outpost";

Create a reusable provider for the Anthropic Messages API, with tool calls, thinking replay, streaming and optional prompt caching. createAgent() rejects an agent model without maxOutputTokens or with reasoning minimal. Each request is sent once, with no retry.

Complete example and detailed rules.

  • optionsRequired
    AnthropicModelProviderOptions
    API key, base URL, request bounds and system-prompt caching. Unknown options fail with code configuration.
  • options.apiKeyRequired
    string
    Explicit Anthropic API key sent in x-api-key; no CLI account or host credential discovery.
  • options.baseUrlOptional
    string | undefined
    Messages API base URL including its version prefix, default https://api.anthropic.com/v1; messages is appended. Credentials, query or fragment fail with code configuration.
  • options.cacheSystemOptional
    boolean | undefined
    Adds an ephemeral cache breakpoint on the system text, default false. Requests without system instructions then fail with code configuration; a cache hit is not guaranteed.
  • options.timeoutMsOptional
    number | undefined
    Request deadline in milliseconds, default 120000, at most 2147483647. While streaming it restarts on each received chunk; expiry rejects with code timeout.
  • options.maxResponseBytesOptional
    number | undefined
    Maximum response body in bytes after decompression, default 8388608 (8 MiB); a streamed response counts all its chunks. A larger response fails with code response.

ModelProvider

export declare function createAnthropicModelProvider(
  options: AnthropicModelProviderOptions,
): ModelProvider;