import type { FetchImpl, Message, Model, ProviderSessionState, ServiceTier, SimpleStreamOptions, StreamFunction, StreamOptions, Usage } from "../types"; import { type AnthropicFetchOptions, type AnthropicMessagesClientLike } from "./anthropic-client"; import type { MessageParam, TextBlockParam } from "./anthropic-wire"; export type AnthropicHeaderOptions = { apiKey: string; baseUrl?: string; isOAuth?: boolean; extraBetas?: string[]; stream?: boolean; modelHeaders?: Record; isCloudflareAiGateway?: boolean; claudeCodeSessionId?: string; claudeCodeBetas?: readonly string[]; }; export declare function normalizeAnthropicBaseUrl(baseUrl?: string): string | undefined; export declare function buildBetaHeader(baseBetas: readonly string[], extraBetas: readonly string[]): string; export declare function buildAnthropicHeaders(options: AnthropicHeaderOptions): Record; type AnthropicCacheControl = NonNullable; /** * Clears the in-session "server rejected fast mode" sticky flag. Call when the * caller is explicitly re-arming `serviceTier: "priority"` (e.g. user toggled * `/fast on` after a previous turn auto-disabled it) so the next request * actually carries `speed: "fast"` again. No-op when the map or state entry * hasn't been materialized yet. */ export declare function clearAnthropicFastModeFallback(providerSessionState: Map | undefined): void; export declare const claudeCodeVersion = "2.1.165"; export declare const claudeAgentSdkVersion = "0.3.165"; export declare const claudeClientVersion = "1.11187.4"; export declare const claudeToolPrefix: string; export declare const claudeCodeSystemInstruction = "You are a Claude agent, built on Anthropic's Claude Agent SDK."; export declare const CLAUDE_CODE_MAX_OUTPUT_TOKENS = 64000; export declare function mapStainlessOs(platform: string): "MacOS" | "Windows" | "Linux" | "FreeBSD" | `Other::${string}`; export declare function mapStainlessArch(arch: string): "x64" | "arm64" | "x86" | `other::${string}`; export declare const claudeCodeHeaders: { "X-Stainless-Retry-Count": string; "X-Stainless-Runtime-Version": string; "X-Stainless-Package-Version": string; "X-Stainless-Runtime": string; "X-Stainless-Lang": string; "X-Stainless-Arch": "arm64" | "x64" | "x86" | `other::${string}`; "X-Stainless-OS": "FreeBSD" | "Linux" | "MacOS" | "Windows" | `Other::${string}`; "X-Stainless-Timeout": string; "anthropic-client-platform": string; "anthropic-client-version": string; }; /** * Wraps a fetch implementation to patch the Claude Code billing-header `cch` * attestation into outgoing request bodies. Bodies without the placeholder * pass through untouched, so installing it on every OAuth flow is safe. */ export declare function wrapFetchForCch(base: FetchImpl): FetchImpl; export declare function isClaudeCloakingUserId(userId: string): boolean; export declare function generateClaudeCloakingUserId(): string; export declare function deriveClaudeDeviceId(installId: string, accountId?: string): string; /** * Resolve the `metadata.user_id` field for an Anthropic Messages request. * * For API-key tokens, an explicit caller-supplied `userId` is forwarded * verbatim and `undefined` yields no metadata. For OAuth tokens the value * must match the Claude Code attribution shape (`isClaudeCloakingUserId` or * the `{session_id, account_uuid?, device_id?}` JSON envelope) — anything * else is dropped and a fresh Claude-Code-style JSON id is generated from * `sessionId`/`accountId` so attribution stays consistent across the main * streaming path and provider-specific request builders (e.g. web search). */ export declare function resolveAnthropicMetadataUserId(userId: unknown, isOAuthToken: boolean, sessionId?: string, accountId?: string): string | undefined; export declare const applyClaudeToolPrefix: (name: string) => string; export declare const stripClaudeToolPrefix: (name: string) => string; export type AnthropicOutputEffort = "low" | "medium" | "high" | "xhigh" | "max"; export type AnthropicEffort = AnthropicOutputEffort | "adaptive"; export type AnthropicThinkingDisplay = "summarized" | "omitted"; export interface AnthropicOptions extends StreamOptions { /** * Enable extended thinking. * For adaptive-capable models (Opus 4.6+, Sonnet 4.6+, Fable/Mythos 5): * uses adaptive thinking (Claude decides when/how much to think). For older * models: uses budget-based thinking with thinkingBudgetTokens. */ thinkingEnabled?: boolean; /** * Token budget for extended thinking (older models only). * Ignored for adaptive-capable models. */ thinkingBudgetTokens?: number; /** * Upstream wire model id override for collapsed effort-tier variants. * Serialized as `requestModelId ?? model.requestModelId ?? model.id`. */ requestModelId?: string; /** * Effort level for adaptive thinking. * Controls how much Claude allocates, or uses "adaptive" for MiniMax's * binary adaptive-thinking tag: * - "max": Always thinks with no constraints * - "high": Always thinks, deep reasoning (default) * - "medium": Moderate thinking, may skip for simple queries * - "low": Minimal thinking, skips for simple tasks * - "adaptive": Sends `thinking.type: "adaptive"` without `output_config.effort` * Ignored for older models. */ effort?: AnthropicEffort; /** * Optional reasoning level fallback for direct Anthropic provider usage. * Converted to adaptive effort when effort is not explicitly provided. */ reasoning?: SimpleStreamOptions["reasoning"]; /** * Controls how Anthropic returns thinking content when the selected thinking * transport supports a display option. Defaults to "summarized" where the * API accepts it. */ thinkingDisplay?: AnthropicThinkingDisplay; interleavedThinking?: boolean; toolChoice?: "auto" | "any" | "none" | { type: "tool"; name: string; }; betas?: string[] | string; /** * Realization of `serviceTier: "priority"` on Anthropic models. When * `"priority"`, sets `speed: "fast"` on the request and appends the * `fast-mode-2026-02-01` beta header. Anthropic rejects unsupported models * with `invalid_request_error`, which triggers an in-provider one-shot * fallback (see `fastModeDisabled` provider state). * * Other `ServiceTier` values are currently ignored on this provider. */ serviceTier?: ServiceTier; /** Force OAuth bearer auth mode for proxy tokens that don't match Anthropic token prefixes. */ isOAuth?: boolean; /** * Pre-built Anthropic Messages client. When provided, skips internal client * construction entirely. Accepts any structurally compatible client, * including SDK clients such as `AnthropicVertex`. */ client?: AnthropicMessagesClientLike; } export type AnthropicClientOptionsArgs = { model: Model<"anthropic-messages">; apiKey: string; extraBetas?: string[]; stream?: boolean; interleavedThinking?: boolean; headers?: Record; dynamicHeaders?: Record; isOAuth?: boolean; hasTools?: boolean; thinkingEnabled?: boolean; thinkingDisplay?: AnthropicThinkingDisplay; fetch?: FetchImpl; claudeCodeSessionId?: string; }; export type AnthropicClientOptionsResult = { isOAuthToken: boolean; apiKey: string | null; authToken?: string | null; baseURL?: string; maxRetries: number; defaultHeaders: Record; fetch?: FetchImpl; fetchOptions?: AnthropicFetchOptions; }; /** * Returns env-supplied custom headers (`ANTHROPIC_CUSTOM_HEADERS`) when they * should be forwarded to the upstream endpoint. * * Foundry mode forwards them unconditionally. Outside Foundry, they're applied * only when the configured base URL is a non-Anthropic host — i.e. an * enterprise/corporate gateway that may require its own proprietary auth * header. Stock `api.anthropic.com` would reject unknown headers, so they're * omitted there. */ export declare function resolveAnthropicCustomHeadersForBaseUrl(baseUrl: string | undefined): Record | undefined; /** * Whether an Anthropic (or Copilot-over-Anthropic) stream error should be * retried. The classification lives in {@link AIError.isProviderRetryableError}; * this wrapper injects the Copilot-specific `model_not_supported` transient * check, which the error module must not import directly. */ export declare function isProviderRetryableError(error: unknown, provider?: string): boolean; export type AnthropicUsageLike = { cache_creation?: { ephemeral_5m_input_tokens?: number | null; ephemeral_1h_input_tokens?: number | null; } | null; server_tool_use?: { web_search_requests?: number | null; web_fetch_requests?: number | null; } | null; }; /** * Capture Anthropic's optional cache-creation TTL breakdown and server-tool-use * counters into the harness Usage shape. Omitted/null fields are no-ops; explicit * zero-valued objects clear prior extras from earlier stream usage snapshots. */ export declare function applyAnthropicUsageExtras(usage: Usage, source: AnthropicUsageLike): void; /** * Public entry: wrap the single-attempt streamer with bounded empty-completion * retries (a benign terminal stop carrying no content/usage would otherwise * stall the agent loop). The inner attempt keeps its own provider-failure retry * loop; this layer only re-issues a fresh request on an empty success. Shared * with the OpenAI-completions provider via `withEmptyCompletionRetry`. */ export declare const streamAnthropic: StreamFunction<"anthropic-messages">; export type AnthropicSystemBlock = { type: "text"; text: string; cache_control?: AnthropicCacheControl; }; type SystemBlockOptions = { includeClaudeCodeInstruction?: boolean; extraInstructions?: string[]; /** Text of the first user message — used as fingerprint seed for the billing header. */ firstUserMessageText?: string; cacheControl?: AnthropicCacheControl; }; export declare function buildAnthropicSystemBlocks(systemPrompt: readonly string[] | undefined, options?: SystemBlockOptions): AnthropicSystemBlock[] | undefined; export declare function normalizeExtraBetas(betas?: string[] | string): string[]; export declare function buildAnthropicClientOptions(args: AnthropicClientOptionsArgs): AnthropicClientOptionsResult; /** * A single Anthropic conversation turn, including the mid-conversation * `system` role (Opus 4.8+ and Fable/Mythos 5). */ export type AnthropicMessageParam = MessageParam; export declare function convertAnthropicMessages(messages: Message[], model: Model<"anthropic-messages">, isOAuthToken: boolean): AnthropicMessageParam[]; export declare function normalizeAnthropicToolSchema(schema: unknown): unknown; export {};