import {z} from 'zod' export type GetApiAnthropicV1MessagesBatchesArgs = {'x-model-provider'?: string | undefined, page_size?: number | undefined, page_token?: string | undefined}; export type GetApiAnthropicV1MessagesBatchesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAnthropicV1MessagesBatchesResponse = z.object({data: z.array(z.object({id: z.string().optional(), type: z.string().optional(), processing_status: z.enum(["in_progress", "ended", "canceling"]).optional(), request_counts: z.object({processing: z.number().int().optional(), succeeded: z.number().int().optional(), errored: z.number().int().optional(), canceled: z.number().int().optional(), expired: z.number().int().optional()}).optional(), ended_at: z.string().nullable().optional(), created_at: z.string().optional(), expires_at: z.string().optional(), archived_at: z.string().nullable().optional(), cancel_initiated_at: z.string().nullable().optional(), results_url: z.string().nullable().optional()})).optional(), has_more: z.boolean().optional(), first_id: z.string().optional(), last_id: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List batch jobs (Anthropic format) * * GET /anthropic/v1/messages/batches * * Also accepts auth: BasicAuth, VirtualKeyAuth, ApiKeyAuth */ export const getApiAnthropicV1MessagesBatches = async (args: GetApiAnthropicV1MessagesBatchesArgs, options?: GetApiAnthropicV1MessagesBatchesOptions) => { const {baseUrl = "http://localhost:8080", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-model-provider'] != null) headers.set("x-model-provider", String(args['x-model-provider'])) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.page_token != null) query.append("page_token", String(args.page_token)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/anthropic/v1/messages/batches${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiAnthropicV1MessagesBatchesResponse, await res.json()) };