@ai-sdk/anthropic
Version:
The **[Anthropic provider](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Anthropic Messages API](https://docs.anthropic.com/claude/reference/messages_post).
27 lines (23 loc) • 620 B
text/typescript
import {
createJsonErrorResponseHandler,
InferSchema,
lazySchema,
zodSchema,
} from '@ai-sdk/provider-utils';
import { z } from 'zod/v4';
export const anthropicErrorDataSchema = lazySchema(() =>
zodSchema(
z.object({
type: z.literal('error'),
error: z.object({
type: z.string(),
message: z.string(),
}),
}),
),
);
export type AnthropicErrorData = InferSchema<typeof anthropicErrorDataSchema>;
export const anthropicFailedResponseHandler = createJsonErrorResponseHandler({
errorSchema: anthropicErrorDataSchema,
errorToMessage: data => data.error.message,
});