You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Minimal reproduction: any Think agent using @ai-sdk/anthropic or @ai-sdk/openai with tool() + Zod v4 parameters. The zod-to-json-schema package (used internally by the AI SDK) returns {} for Zod v4 schemas, so the provider sends input_schema without type: 'object'. Both Anthropic and OpenAI APIs reject this.
This blocks Think from working with any external LLM provider. Only Workers AI models work because they don't validate tool schemas strictly.
import{Think}from"@cloudflare/think";import{createAnthropic}from"@ai-sdk/anthropic";import{tool}from"ai";import{z}from"zod";import{routeAgentRequest}from"agents";interfaceEnv{AI: any;ANTHROPIC_API_KEY: string;}exportclassMyAgentextendsThink<Env>{maxSteps=5;getModel(){returncreateAnthropic({apiKey: this.env.ANTHROPIC_API_KEY})("claude-sonnet-4-20250514");}getSystemPrompt(){return"You are a helpful assistant with tools.";}asyncbeforeTurn(){return{activeTools: ["get_weather"]};}getTools(){return{get_weather: tool({description: "Get weather for a city",parameters: z.object({city: z.string().describe("City name")}),execute: async({ city })=>({ city,temp: 72,condition: "sunny"}),}),};}}exportdefault{asyncfetch(request: Request,env: Env){return(awaitrouteAgentRequest(request,env))||newResponse("Not found",{status: 404});},}satisfiesExportedHandler<Env>;
Steps
Deploy with npx wrangler deploy
Set ANTHROPIC_API_KEY secret
Connect via WebSocket to /agents/my-agent/test1
Send cf_agent_use_chat_request with any message
Result
tools.0.custom.input_schema.type: Field required
Same error with @ai-sdk/openai + GPT-4o:
Invalid schema for function 'get_weather': schema must be a JSON Schema of 'type: "object"', got 'type: "None"'.
zod-to-json-schema doesn't support Zod v4. The AI SDK uses it internally to convert tool parameters before sending to providers. Zod v4 has a native .toJsonSchema() method that works correctly.
Works fine with Workers AI models (kimi-k2.5) because they don't validate input_schema strictly. Breaks with any external provider (Anthropic, OpenAI) that validates schema shape.
Live repro deployed at: think-anthropic-repro.evan-ratner.workers.dev
Hi @eratner15 . This actually isn't a zod problem. It looks like you're using parameters in the tool definition, which was correct syntax in AI SDK v4, but not in v6 as you've currently got installed. In v6, it's called inputSchema, and retrying your example with that line produces the correct JSON schema for both Anthropic and OpenAI.
I'm going to close this, but please reopen if inputSchema doesn't work for you.
Activity
v0.15.0: demo-ready — EDGAR fix, agent stabilized, bug filed
eratner15 commentedon Apr 16, 2026
Minimal reproduction: any Think agent using
@ai-sdk/anthropicor@ai-sdk/openaiwithtool()+ Zod v4 parameters. Thezod-to-json-schemapackage (used internally by the AI SDK) returns{}for Zod v4 schemas, so the provider sendsinput_schemawithouttype: 'object'. Both Anthropic and OpenAI APIs reject this.This blocks Think from working with any external LLM provider. Only Workers AI models work because they don't validate tool schemas strictly.
Happy to help test a fix. cc @threepointone @geelen
threepointone commentedon Apr 16, 2026
can you actually make a small repro? because this should just work, unless you're using older versions of any dependencies. happy to dive into it
eratner15 commentedon Apr 16, 2026
Minimal repro
Fresh project, all latest versions:
wrangler.jsonc{ "name": "think-anthropic-repro", "main": "src/index.ts", "compatibility_date": "2026-04-16", "compatibility_flags": ["nodejs_compat"], "durable_objects": { "bindings": [{ "class_name": "MyAgent", "name": "MyAgent" }] }, "migrations": [{ "new_sqlite_classes": ["MyAgent"], "tag": "v1" }], "ai": { "binding": "AI" } }src/index.tsSteps
npx wrangler deployANTHROPIC_API_KEYsecret/agents/my-agent/test1cf_agent_use_chat_requestwith any messageResult
Same error with
@ai-sdk/openai+ GPT-4o:Root cause trace
zod-to-json-schemadoesn't support Zod v4. The AI SDK uses it internally to convert tool parameters before sending to providers. Zod v4 has a native.toJsonSchema()method that works correctly.Works fine with Workers AI models (kimi-k2.5) because they don't validate
input_schemastrictly. Breaks with any external provider (Anthropic, OpenAI) that validates schema shape.Live repro deployed at:
think-anthropic-repro.evan-ratner.workers.devthreepointone commentedon Aug 5, 2026
we should try to move to standard schema
cjol commentedon Aug 5, 2026
Hi @eratner15 . This actually isn't a zod problem. It looks like you're using
parametersin the tool definition, which was correct syntax in AI SDK v4, but not in v6 as you've currently got installed. In v6, it's calledinputSchema, and retrying your example with that line produces the correct JSON schema for both Anthropic and OpenAI.I'm going to close this, but please reopen if
inputSchemadoesn't work for you.