-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: Add GPT-5 Azure responses API support #6893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Detect GPT-5 models when using Azure OpenAI provider - Use responses API endpoint with "input" parameter instead of chat completions "messages" - Support GPT-5 specific parameters: reasoning effort (including minimal), verbosity, and reasoning summary - Handle responses API streaming format for text, reasoning, and usage events - Add comprehensive tests for GPT-5 Azure integration Fixes #6862
const reader = body.getReader() | ||
const decoder = new TextDecoder() | ||
let buffer = "" | ||
let hasContent = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable 'hasContent' is set in the streaming response handler but never used. Consider removing it if it isn’t needed.
let hasContent = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
/** | ||
* Checks if the model ID is a GPT-5 model | ||
*/ | ||
private isGpt5Model(modelId: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice there's a duplicate method here. The isGpt5Model()
is defined twice - once at line 424 and the logic is already used inline at line 93. Should we consolidate to use a single method definition to avoid duplication?
// Azure URLs typically look like: https://<resource>.openai.azure.com/openai/responses?api-version=... | ||
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/) | ||
const azureBaseUrl = urlParts ? urlParts[1] : baseUrl | ||
const responsesUrl = `${azureBaseUrl}/openai/responses` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the Azure API version validated anywhere? For GPT-5 responses API, this parameter seems critical. Could we add validation to ensure it's present and in the expected format (e.g., '2025-04-01-preview' or later)?
|
||
// Extract the base URL without the path for Azure endpoints | ||
// Azure URLs typically look like: https://<resource>.openai.azure.com/openai/responses?api-version=... | ||
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex pattern for URL extraction might be fragile with certain URL formats. Would it be safer to use the URL constructor for parsing? Something like:
const urlParts = baseUrl.match(/^(https?:\/\/[^\/]+)(\/.*)?$/) | |
const url = new URL(baseUrl); | |
const azureBaseUrl = `${url.protocol}//${url.host}`; | |
const responsesUrl = `${azureBaseUrl}/openai/responses`; |
const reasoningEffort = this.getGpt5ReasoningEffort(reasoning) | ||
|
||
// Build request body for GPT-5 responses API | ||
const requestBody: any = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requestBody is typed as any
. Could we create a proper TypeScript interface for the GPT-5 request body to improve type safety? This would help catch potential issues at compile time.
} | ||
} | ||
// Handle reasoning delta events | ||
else if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we handling all possible GPT-5 streaming events? I'm wondering if there might be events like response.reasoning_effort.updated
or other GPT-5 specific events we should handle. The Azure docs might have a complete list.
@@ -783,6 +836,166 @@ describe("OpenAiHandler", () => { | |||
) | |||
}) | |||
}) | |||
|
|||
describe("GPT-5 Azure Support", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Though I'm wondering if we should add tests for error scenarios like malformed SSE data or network failures during streaming? These edge cases could help ensure robust error handling.
This is the implementation of this api, correct? If so, can it be also added on OpenAI provider? |
Also make sure you are giving the api the previous_response_id in a multi-turn conversion |
|
Issue needs proper scoping |
Summary
This PR fixes the issue where GPT-5 models on Azure OpenAI deployments were failing with a
400 Unsupported parameter: "messages"
error. The problem was that GPT-5 models use the new responses API which expects an "input" parameter instead of the chat completions API "messages" parameter.Changes
/openai/responses
)Testing
Related Issue
Fixes #6862
How to Test
https://<YOUR-RESOURCE>.openai.azure.com/openai/responses?api-version=2025-04-01-preview
gpt-5
2025-04-01-preview
cc @SannidhyaSah
Important
Fixes GPT-5 Azure API support by implementing the responses API and adding comprehensive tests.
400 Unsupported parameter: "messages"
error for GPT-5 models on Azure by switching to the responses API.handleGpt5ResponsesAPI()
inopenai.ts
to format requests for GPT-5 models using Azure.processUsageMetrics()
inopenai.ts
to handle both GPT-5 and standard formats.openai.spec.ts
for GPT-5 Azure support, verifying API endpoint usage, parameter formatting, and response handling.isGpt5Model()
andformatInputForResponsesAPI()
helper functions inopenai.ts
.createMessage()
inopenai.ts
to detect and handle GPT-5 models on Azure.This description was created by
for ecf2e1a. You can customize this summary. It will automatically update as commits are pushed.