Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
23 lines
718 B
TypeScript
23 lines
718 B
TypeScript
import { z } from "zod/v4"
|
|
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils"
|
|
|
|
export const openaiErrorDataSchema = 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 OpenAIErrorData = z.infer<typeof openaiErrorDataSchema>
|
|
|
|
export const openaiFailedResponseHandler: any = createJsonErrorResponseHandler({
|
|
errorSchema: openaiErrorDataSchema,
|
|
errorToMessage: (data) => data.error.message,
|
|
})
|