1import Anthropic from "@anthropic-ai/sdk";
2import { zodOutputFormat } from "@anthropic-ai/sdk/helpers/zod";
3import { z } from "zod";
4
5const client = new Anthropic();
6const Booking = z.object({
7 name: z.string(),
8 party_size: z.number(),
9 day: z.string(),
10 time: z.string(),
11});
12
13const response = await client.messages.parse({
14 model: "claude-haiku-5-5",
15 max_tokens: 1024,
16 output_config: { format: zodOutputFormat(Booking) },
17 messages: [{
18 role: "user",
19 content: "Get the booking details from: Table for 4 at Luigi's, Friday 7:30pm, under the name Okafor.",
20 }],
21});
22
23console.log(response.parsed_output); // typed as { name, party_size, day, time }