/** * @file A client for Anthropic's Message Batches endpoint. The corpus labeling tools submit their requests through it. * * A batch is asynchronous: `createMessageBatch` returns an id, `readMessageBatch` reports its state, * and `readMessageBatchResults` returns one line per request once the state is `ended`. * Result lines arrive in any order, so a caller joins them to its requests by `custom_id`. */ import { APIClient } from "@mailwoman/core/api"; /** * The most requests one batch accepts. */ export declare const MAX_BATCH_REQUESTS = 100000; /** * One Messages request inside a batch, addressed by a caller-chosen id of at most 64 characters. */ export interface MessageBatchRequest { custom_id: string; params: Record; } /** * The state of a submitted batch. */ export interface MessageBatch { id: string; processing_status: "in_progress" | "canceling" | "ended"; request_counts: { processing: number; succeeded: number; errored: number; canceled: number; expired: number; }; results_url: string | null; } /** * Token counts the API bills a response for. */ export interface MessageUsage { input_tokens: number; output_tokens: number; cache_creation_input_tokens?: number | null; cache_read_input_tokens?: number | null; } /** * One request's outcome in a finished batch. * * `message` is present only when `type` is `succeeded`. */ export interface MessageBatchResult { custom_id: string; result: { type: "succeeded" | "errored" | "canceled" | "expired"; message?: { content: Array<{ type: string; text?: string; }>; stop_reason: string | null; usage: MessageUsage; }; error?: unknown; }; } /** * Dollars per million tokens for one model on the batch endpoint. */ export interface TokenPrice { input: number; output: number; } /** * Creates the client every batch call shares. * * @throws When `ANTHROPIC_API_KEY` is unset. */ export declare function createAnthropicClient(): APIClient; /** * Sends one Messages request outside a batch, at the standard price, * and returns it in a batch result's shape. * * A labeling tool sends one of these before a batch to confirm the API accepts its * parameters and to measure the tokens one request uses. */ export declare function createMessage(client: APIClient, request: MessageBatchRequest): Promise; /** * Submits `requests` as one batch and returns its initial state. * * @throws When `requests` is empty or exceeds `MAX_BATCH_REQUESTS`. */ export declare function createMessageBatch(client: APIClient, requests: MessageBatchRequest[]): Promise; /** * Reads the current state of the batch `id`. */ export declare function readMessageBatch(client: APIClient, id: string): Promise; /** * Reads every result line of the finished batch `id`. * * @throws When the batch is still in progress, or when a line of the result file fails to parse. */ export declare function readMessageBatchResults(client: APIClient, id: string): Promise; /** * Parses the JSONL body of a batch's results, as the API returns it or as a run saved it. * * @param source Where the body came from, as an error states it. * @throws When a line fails to parse or lacks a request id or outcome, or when the body holds no result. */ export declare function parseMessageBatchResults(body: string, source: string): MessageBatchResult[]; /** * Returns the text of a succeeded result, or `null` for any other outcome * or a response that stopped at `max_tokens`. */ export declare function resultText(result: MessageBatchResult): string | null; /** * Sums the dollars the succeeded results cost at `price`. */ export declare function batchCostUSD(results: readonly MessageBatchResult[], price: TokenPrice): number; //# sourceMappingURL=batches.d.ts.map