import { AnthropicApiError, AnthropicConnectionError, AnthropicConnectionTimeoutError } from "../error"; export { AnthropicApiError, AnthropicConnectionError, AnthropicConnectionTimeoutError }; import type { FetchImpl } from "../types"; import type { MessageCreateParamsStreaming } from "./anthropic-wire"; /** Per-request options accepted by {@link AnthropicMessages.create}. */ export interface AnthropicRequestOptions { signal?: AbortSignal; /** Pre-response timeout in milliseconds. */ timeout?: number; /** Per-request retry budget override. */ maxRetries?: number; /** Per-request headers merged after client defaults. */ headers?: Record; } /** * Extra `RequestInit` fields merged into every fetch call. Bun extends * `RequestInit` with a `tls` option used for the Claude Code TLS profile and * Foundry mTLS. Core request fields (`method`, `headers`, `body`, `signal`) * are owned by the client and cannot be overridden from here — the timeout * controller's signal in particular must always win. */ export type AnthropicFetchOptions = RequestInit & { tls?: { rejectUnauthorized?: boolean; serverName?: string; ciphers?: string; ca?: string | string[]; cert?: string; key?: string; }; /** Bun extension: see {@link FetchWithRetryOptions.timeout} — `false` disables Bun's native fetch TTFT timeout (issue #2422). */ timeout?: number | false; }; export interface AnthropicClientOptions { /** Sent as `X-Api-Key` unless the header is already present in `defaultHeaders`. */ apiKey?: string | null; /** Sent as `Authorization: Bearer ` unless the header is already present in `defaultHeaders`. */ authToken?: string | null; baseURL?: string | null; maxRetries?: number; /** Pre-response timeout in milliseconds. Defaults to 10 minutes. */ timeout?: number; defaultHeaders?: Record; fetch?: FetchImpl; fetchOptions?: AnthropicFetchOptions; } /** Server-suggested delay (`retry-after-ms`, then `retry-after` seconds or HTTP date). */ export declare function retryDelayFromHeaders(headers: Headers | undefined): number | undefined; export declare function calculateAnthropicRetryDelayMs(attempt: number): number; /** * Lazy in-flight request handle. The HTTP request starts on the first * `asResponse()` call; subsequent calls return the same promise. * * Shape-compatible with the SDK's `APIPromise.asResponse()` so * `getAnthropicStreamResponse` treats internal and injected clients uniformly. */ export declare class AnthropicApiRequest { #private; constructor(start: () => Promise); asResponse(): Promise; } /** * `messages` resource. `create` lives on the prototype so tests can intercept * every outgoing request with `vi.spyOn(AnthropicMessages.prototype, "create")`. */ export declare class AnthropicMessages { #private; constructor(client: AnthropicMessagesClient, path: string); create(params: MessageCreateParamsStreaming, options?: AnthropicRequestOptions): AnthropicApiRequest; } /** * Structural interface satisfied by both {@link AnthropicMessagesClient} and * SDK-style clients (e.g. `AnthropicVertex`), so callers can inject an * alternative Messages-API client via `AnthropicOptions.client`. */ export interface AnthropicMessagesClientLike { messages: { create(params: MessageCreateParamsStreaming, options?: AnthropicRequestOptions): unknown; }; beta?: { messages: { create(params: MessageCreateParamsStreaming, options?: AnthropicRequestOptions): unknown; }; }; } export declare class AnthropicMessagesClient implements AnthropicMessagesClientLike { #private; readonly messages: AnthropicMessages; readonly beta: { readonly messages: AnthropicMessages; }; constructor(options: AnthropicClientOptions); request(path: string, params: MessageCreateParamsStreaming, options?: AnthropicRequestOptions): AnthropicApiRequest; }