-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
ai/providerbugSomething isn't working as documentedSomething isn't working as documentedprovider/deepseekIssues related to the @ai-sdk/deepseek providerIssues related to the @ai-sdk/deepseek providerprovider/openai-compatible
Description
Bug Report: OpenAI-compatible providers fail with tools - missing "type": "object" in JSON Schema
Description
When using tools with OpenAI-compatible providers that strictly validate JSON schemas (like DeepSeek), all tool calls fail with the error:
Invalid schema for function 'functionName': schema must be a JSON Schema of 'type: "object"', got 'type: null'.
Root Cause
The bug is in the OpenAI-compatible provider used by DeepSeek. When converting tool schemas, the AI SDK creates JSON schemas without the required "type": "object" field.
Location in source code:
@ai-sdk/openai-compatible/dist/index.jsline 239: Directly passestool.inputSchemawithout validation@ai-sdk/provider-utils/dist/index.jslines 1031-1033: Creates schema withouttypefield:
jsonSchema({
properties: {},
additionalProperties: false
})Reproduction
import { streamText } from 'ai';
import { deepseek } from '@ai-sdk/deepseek';
import { z } from 'zod';
const result = await streamText({
model: deepseek('deepseek-chat'),
messages: [{ role: 'user', content: 'What is the weather?' }],
tools: {
getWeather: {
description: 'Get weather',
parameters: z.object({
location: z.string(),
}),
execute: async () => ({ weather: 'sunny' }),
},
},
});What AI SDK sends (incorrect):
{
"type": "function",
"function": {
"name": "getWeather",
"description": "Get weather",
"parameters": {
"properties": {},
"additionalProperties": false
}
}
}What DeepSeek expects (correct):
{
"type": "function",
"function": {
"name": "getWeather",
"description": "Get weather",
"parameters": {
"type": "object", // <-- This is missing!
"properties": {
"location": {
"type": "string"
}
},
"required": ["location"]
}
}
}Verification
Direct API call to DeepSeek works fine with proper schema:
curl -X POST https://api.deepseek.com/v1/chat/completions \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "What is the weather?"}],
"tools": [{
"type": "function",
"function": {
"name": "getWeather",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}}
}
}
}]
}'Proposed Fix
In @ai-sdk/provider-utils, the jsonSchema function should include "type": "object":
function jsonSchema(jsonSchema2, { validate } = {}) {
// Ensure type: 'object' is set for object schemas
if (jsonSchema2.properties && !jsonSchema2.type) {
jsonSchema2.type = 'object';
}
// ... rest of function
}Or in the asSchema function:
function asSchema(schema) {
return schema == null ? jsonSchema({
type: 'object', // Add this line
properties: {},
additionalProperties: false
}) : isSchema(schema) ? schema : zodSchema(schema);
}Environment
- @ai-sdk/deepseek: 1.0.3
- @ai-sdk/openai-compatible: 1.0.3
- @ai-sdk/provider-utils: 3.0.1
- ai: 5.0.8
Impact
This bug prevents all tool usage with DeepSeek through the AI SDK, making it impossible to use function calling with this provider.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ai/providerbugSomething isn't working as documentedSomething isn't working as documentedprovider/deepseekIssues related to the @ai-sdk/deepseek providerIssues related to the @ai-sdk/deepseek providerprovider/openai-compatible