Skip to content

feat(azure): Support Responses API alongside Completions API (#1337)#1442

Open
zjl4616 wants to merge 1 commit into
karthink:masterfrom
zjl4616:azure-responses-api-support
Open

feat(azure): Support Responses API alongside Completions API (#1337)#1442
zjl4616 wants to merge 1 commit into
karthink:masterfrom
zjl4616:azure-responses-api-support

Conversation

@zjl4616

@zjl4616 zjl4616 commented Jun 5, 2026

Copy link
Copy Markdown

Summary

Adds transparent dual-backend support to gptel-make-azure, enabling it to use the OpenAI Responses API for OpenAI models (GPT-4o, GPT-5, etc.) while falling back to the Completions API for non-OpenAI models — identical to how gptel-gh (GitHub Copilot) handles this.

Closes #1337.

Motivation

Azure OpenAI now serves OpenAI models that expect the Responses API, but also hosts non-OpenAI models (Llama, Mistral, etc.) that only support the Completions API. The current gptel-make-azure only supports Completions, causing errors with newer OpenAI models.

Implementation

Follows the exact pattern established by gptel-gh.el:

  1. New struct gptel--azure — inherits from gptel-openai, adds a responses-backend field storing an embedded gptel-openai-responses instance.

  2. 11 cl-defmethod dispatchers — each checks (gptel--model-capable-p 'responses-api gptel-model) and routes to either the responses backend or falls through to the parent completions method:

    • gptel-curl--parse-stream
    • gptel--parse-response
    • gptel--request-data
    • gptel--parse-schema
    • gptel--parse-tools
    • gptel--inject-tool-call
    • gptel--parse-tool-results
    • gptel--inject-prompt
    • gptel--parse-list
    • gptel--parse-buffer
    • gptel--inject-media
  3. Modified gptel-make-azure — uses the new struct, creates an embedded responses backend, dynamically selects endpoint URL based on model capability.

Usage

Users mark models with responses-api capability:

(gptel-make-azure "Azure-OpenAI"
  :host "myresource.openai.azure.com"
  :endpoint "/openai/deployments/gpt-5/chat/completions?api-version=2025-04-01-preview"
  :key "..."
  :models '((gpt-5 :capabilities (responses-api))
            gpt-4o))
  • gpt-5 → automatically uses Responses API (/openai/deployments/gpt-5/responses?api-version=...)
  • gpt-4o → falls back to Completions API (existing behavior)

Backward Compatibility

✅ Fully backward compatible. Existing Azure configurations work unchanged. Models without responses-api capability continue using the Completions API exactly as before.

Changes

  • gptel-openai.el: +124/-16 lines (single file change)
    • New gptel--azure struct definition
    • 11 dispatch methods
    • Refactored gptel-make-azure constructor

Add support for the OpenAI Responses API to the Azure backend,
following the same dual-backend dispatch pattern used by GitHub
Copilot (gptel-gh.el).

Changes:
- Define gptel--azure struct inheriting from gptel-openai with a
  responses-backend field
- Add 11 cl-defmethod dispatchers that check for responses-api
  model capability and delegate to the embedded responses backend
- Modify gptel-make-azure to create an embedded
  gptel-openai-responses backend instance and use dynamic URL
  selection based on model capability
- Enhance docstring with model capability documentation
- Fix typo: 'retuns' -> 'returns'

Models with the responses-api capability will automatically use the
Responses API endpoint (/openai/deployments/{deployment}/responses)
while models without it continue using the Completions API endpoint
(/openai/deployments/{deployment}/chat/completions).

Closes karthink#1337
@karthink

karthink commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR @zjl4616! Please move all the azure-specific code to gptel-openai-extras.el. (If we need even more azure-specific code in the future, we can move it to a dedicated gptel-azure.el feature.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Help wanted: Support for the OpenAI Completions vs Responses API in Azure

2 participants