Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
893 B · 27 lines
TypeScript
12345678910111213141516171819202122232425262728import { 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<typeof openaiCompatibleErrorDataSchema>
export type ProviderErrorStructure<T> = { errorSchema: ZodType<T> errorToMessage: (error: T) => string isRetryable?: (response: Response, error?: T) => boolean}
export const defaultOpenAICompatibleErrorStructure: ProviderErrorStructure<OpenAICompatibleErrorData> = { errorSchema: openaiCompatibleErrorDataSchema, errorToMessage: (data) => data.error.message,}