Schema output with createUnified
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 345
- Avg merge
- 13h 31m
- Merged PRs (30d)
- 1
Description
I was using the same code which is working fine with `createWorkersAI()` to generate schema output with CF hosted models, but when the createUnified() is used to generate a response with external model - The schema is not passed to the provider.
For example, I am using `google-ai-studio/gemini-2.5-flash-lite` here, and I see only `response_type: object` is sent and not the actual schema.
```
const aiGateway = createAiGateway({
accountId: env.CF_ACCOUNT_ID,
gateway: 'test',
});
const unified = createUnified({ apiKey: env.GEMINI_APIKEY });
const model = aiGateway(unified("google-ai-studio/gemini-2.5-flash-lite"));
const schema = Output.object({
schema: z.object({
priority: z.enum(["low", "medium", "high", "urgent"]).optional(),
replyMessage: z.string(),
}),
});
const result = await generateText({
model: model,
messages: messagesArray,
output: schema,
});
```
Schema output is supported in gemini-2.5-flash-lite -
https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#model_support
Contributor guide
Research direction
Start by tracing the createUnified() model path used through createAiGateway(), then compare it with createWorkersAI() while handling generateText() output via Output.object. Reproduce the request with google-ai-studio/gemini-2.5-flash-lite and verify that the provider receives the actual schema rather than only response_type: object.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100