feat: add Responses API support for Azure OpenAI provider#5203
feat: add Responses API support for Azure OpenAI provider#5203devin-ai-integration[bot] wants to merge 3 commits intomainfrom
Conversation
When api='responses' is set on an Azure LLM instance, calls are delegated to the OpenAI Responses API implementation with the Azure resource's /openai/v1/ base URL, reusing the fully-tested OpenAI Responses API code path. New fields on AzureCompletion: - api: Literal['completions', 'responses'] (default: 'completions') - instructions, store, previous_response_id, include, builtin_tools - parse_tool_outputs, auto_chain, auto_chain_reasoning - reasoning_effort, seed, max_completion_tokens Usage: llm = LLM(model='azure/gpt-4o', api='responses', api_key=KEY, endpoint=ENDPOINT) Closes #5202 Co-Authored-By: João <joao@crewai.com>
|
Prompt hidden (unlisted session) |
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: João <joao@crewai.com>
…delegate Addresses Bugbot review feedback - these parameters were silently ignored when using api='responses' mode. Co-Authored-By: João <joao@crewai.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| resource_url = raw_endpoint.rstrip("/") | ||
|
|
||
| api_version = self.api_version or "2024-06-01" | ||
| base_url = f"{resource_url}/openai/v1/?api-version={api_version}" |
There was a problem hiding this comment.
Query parameter in base_url produces malformed request URLs
High Severity
The base_url is constructed with a query parameter (?api-version=...) embedded in it. The OpenAI Python SDK uses httpx's raw_path (which includes the query string) for URL joining, so appending API paths like responses produces malformed URLs such as /openai/v1/?api-version=2024-06-01/responses. Microsoft's official documentation shows the correct format is https://RESOURCE.openai.azure.com/openai/v1/ without any query parameter — the v1 API endpoint doesn't require api-version. All tests pass because they mock delegate.call() and never exercise actual HTTP URL construction.


Summary
Adds support for OpenAI's Responses API when using Azure OpenAI endpoints. When
api="responses"is set,AzureCompletiondelegates to anOpenAICompletioninstance configured with the Azure resource's/openai/v1/?api-version=...base URL, reusing the existing fully-tested OpenAI Responses API code path.Usage:
Chat Completions remains the default (
api="completions") — no breaking changes.New fields on
AzureCompletion:api,instructions,store,previous_response_id,include,builtin_tools,parse_tool_outputs,auto_chain,auto_chain_reasoning,reasoning_effort,seed,max_completion_tokensImplementation approach: Delegation to
OpenAICompletionrather than duplicating the Responses API logic. The delegate is constructed withbase_urlpointing to the Azure/openai/v1/endpoint andapi_keyset to the Azure key.Closes #5202
Review & Testing Checklist for Human
{resource}/openai/v1/?api-version={version}is correct for Azure's Responses API. This is the most critical assumption — the URL construction in_init_responses_delegatestrips/openai/deployments/{model}from the endpoint and rebuilds as/openai/v1/. If Azure uses a different path, nothing will work. Consider testing with a real Azure endpoint.api="responses", the Azurecall()early-returns to the delegate, skipping Azure's_emit_call_started_eventand hook invocations. The OpenAI delegate emits its own events withprovider="openai"— verify this is acceptable for your telemetry/observability pipeline._client/_async_clientareNonein responses mode: Confirm no other code path (e.g.,aclose(), context managers, or BaseLLM methods) accesses these whenapi="responses"in a way that would break.api_versionlike2025-03-01-preview).Notes
Link to Devin session: https://app.devin.ai/sessions/660c36a7889243cab62f8af7b5890723
Note
Medium Risk
Adds a new execution path that bypasses the native Azure client/hook/event flow and relies on correct Azure base-URL construction; misconfiguration could break calls in
api="responses"mode while leaving the default path intact.Overview
Adds an optional
api="responses"mode to the Azure LLM provider that delegatescall()/acall()toOpenAICompletionconfigured with an Azure/openai/v1/?api-version=...base_url, while keeping Chat Completions as the default path.Introduces new Responses-API-related fields (e.g.,
instructions, chaining, built-in tools,max_completion_tokens,reasoning_effort) that are forwarded to the delegate, exposeslast_response_id/reset_chain, updatesto_config_dict()to persist non-defaultapi/reasoning_effort, and adds extensive unit tests covering URL construction, parameter forwarding, delegation behavior, and ensuring the legacy completions clients remain unaffected.Written by Cursor Bugbot for commit 2315422. This will update automatically on new commits. Configure here.