-
Notifications
You must be signed in to change notification settings - Fork 940
Description
What Happened?
When using the Portkey OpenAI-compatible gateway to call Gemini models, complex JSON schemas trigger a Google API error: "A schema in GenerationConfig in the request exceeds the maximum allowed nesting depth."
The schema provided has 4 levels of nesting . While this is technically within Gemini's limit, the OpenAI-to-Gemini translation layer in Portkey likely wraps the schema in additional object properties. This same code works fine when used @ai-sdk/google package.
What Should Have Happened?
The Portkey Gateway should translate the OpenAI-formatted schema into a Gemini-native schema without adding unnecessary nesting depth. It should match the behavior of the Vercel AI SDK Google Provider, which successfully processes this specific schema by mapping it directly to the Gemini Response Schema requirements.
Relevant Code Snippet
// This configuration fails via Portkey's OpenAI wrapper
const model = createOpenAI({
baseURL: 'https://api.portkey.ai',
apiKey: config.portkey.apiKey,
headers: { 'x-portkey-metadata': metadata },
})(`${config.portkey.googleProvider}/${modelName}`);
const schema = z.object({
tasks: z.array( // Level 1
z.object({
title: z.string(),
stories: z.array( // Level 2
z.object({
title: z.string(),
acceptance_criteria: z.array(z.string()), // Level 3/4
figma_frame_image_urls: z.array(z.string()), // Level 3/4
}),
),
}),
),
});
// Error occurs here
const { object } = await generateObject({
model,
schema,
prompt: "...",
});