import { z, type ZodType } from "zod/v4" export const openaiCompatibleErrorDataSchema = z.object({ error: z.object({ message: z.string(), // The additional information below is handled loosely to support // OpenAI-compatible providers that have slightly different error // responses: type: z.string().nullish(), param: z.any().nullish(), code: z.union([z.string(), z.number()]).nullish(), }), }) export type OpenAICompatibleErrorData = z.infer export type ProviderErrorStructure = { errorSchema: ZodType errorToMessage: (error: T) => string isRetryable?: (response: Response, error?: T) => boolean } export const defaultOpenAICompatibleErrorStructure: ProviderErrorStructure = { errorSchema: openaiCompatibleErrorDataSchema, errorToMessage: (data) => data.error.message, }