fix: map Responses API text.format to response_format in chat completions conversion#5621
Open
ink-the-squid wants to merge 1 commit intoHelicone:mainfrom
Open
Conversation
…ions conversion When the AI Gateway converts Responses API requests to Chat Completions format for providers like Azure that don't natively support the Responses API, the structured output schema (text.format) was being dropped. The toChatCompletions() function only mapped body.response_format (which doesn't exist in Responses API requests) and ignored body.text.format (where structured output is actually specified in the Responses API). This caused structured output requests through AI Gateway BYOK to return plain text instead of JSON, breaking Pydantic validation on the client side. Changes: - Add text.format type to ResponsesRequestBody (was missing) - Map body.text.format -> response_format in toChatCompletions() - Handles json_schema type with name, description, schema, strict fields - Falls back to body.response_format for backward compatibility Fixes: AI Gateway structured output dropping for Azure BYOK endpoints
|
@ink-the-squid is attempting to deploy a commit to the Helicone Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using the Responses API (
/v1/responses) through the AI Gateway with BYOK Azure endpoints, structured output (text.formatwithjson_schema) is silently dropped. The provider returns plain text instead of structured JSON, breakingclient.responses.parse()and Pydantic validation.Works: Azure direct, OAI proxy, raw OpenAI
Fails: AI Gateway BYOK → Azure
Root Cause
The
toChatCompletions()function converts Responses API requests to Chat Completions format for providers that don't natively support the Responses API (like Azure). It was mappingbody.response_format(Chat Completions field) but ignoringbody.text.format(where structured output is actually specified in the Responses API).In the Responses API, structured output is:
{"text": {"format": {"type": "json_schema", "schema": {...}}}}In Chat Completions, it's:
{"response_format": {"type": "json_schema", "json_schema": {"schema": {...}}}}The conversion was missing entirely.
Fix
formatfield toResponsesRequestBody.texttype definitionbody.text.format→response_formatintoChatCompletions()json_schematype with name, description, schema, strictbody.response_formatfor backward compatibilityFiles Changed
packages/llm-mapper/transform/types/responses.ts— addedtext.formattypepackages/llm-mapper/transform/providers/responses/request/toChatCompletions.ts— mapping logic