Skip to content

Commit 10ef7ff

Browse files
feat: add support for zod@4 schemas (#1666)
Co-authored-by: Robert Craigie <[email protected]>
1 parent 2591c21 commit 10ef7ff

19 files changed

+1227
-65
lines changed

examples/parsing-run-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import OpenAI from 'openai';
2-
import z from 'zod/v3';
2+
import z from 'zod/v4'; // Also works for 'zod/v3'
33
import { zodFunction } from 'openai/helpers/zod';
44

55
const Table = z.enum(['orders', 'customers', 'products']);

examples/parsing-stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zodResponseFormat } from 'openai/helpers/zod';
22
import OpenAI from 'openai/index';
3-
import { z } from 'zod/v3';
3+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
44

55
const Step = z.object({
66
explanation: z.string(),

examples/parsing-tools-stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zodFunction } from 'openai/helpers/zod';
22
import OpenAI from 'openai/index';
3-
import { z } from 'zod/v3';
3+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
44

55
const GetWeatherArgs = z.object({
66
city: z.string(),

examples/parsing-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zodFunction } from 'openai/helpers/zod';
22
import OpenAI from 'openai/index';
3-
import { z } from 'zod/v3';
3+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
44

55
const Table = z.enum(['orders', 'customers', 'products']);
66

examples/parsing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zodResponseFormat } from 'openai/helpers/zod';
22
import OpenAI from 'openai/index';
3-
import { z } from 'zod/v3';
3+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
44

55
const Step = z.object({
66
explanation: z.string(),

examples/responses/streaming-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { OpenAI } from 'openai';
44
import { zodResponsesFunction } from 'openai/helpers/zod';
5-
import { z } from 'zod/v3';
5+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
66

77
const Table = z.enum(['orders', 'customers', 'products']);
88
const Column = z.enum([

examples/responses/structured-outputs-tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { OpenAI } from 'openai';
44
import { zodResponsesFunction } from 'openai/helpers/zod';
5-
import { z } from 'zod/v3';
5+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
66

77
const Table = z.enum(['orders', 'customers', 'products']);
88
const Column = z.enum([

examples/responses/structured-outputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { OpenAI } from 'openai';
44
import { zodTextFormat } from 'openai/helpers/zod';
5-
import { z } from 'zod/v3';
5+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
66

77
const Step = z.object({
88
explanation: z.string(),

examples/tool-call-helpers-zod.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import OpenAI from 'openai';
44
import { zodFunction } from 'openai/helpers/zod';
5-
import { z } from 'zod/v3';
5+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
66

77
// gets API Key from environment variable OPENAI_API_KEY
88
const openai = new OpenAI();

examples/ui-generation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import OpenAI from 'openai';
2-
import { z } from 'zod/v3';
2+
import { z } from 'zod/v4'; // Also works for 'zod/v3'
33
import { zodResponseFormat } from 'openai/helpers/zod';
44

55
const openai = new OpenAI();

0 commit comments

Comments
 (0)