Skip to content

Port from Chat Completions API to Responses API#292

Open
pamelafox wants to merge 2 commits intomainfrom
responses-api
Open

Port from Chat Completions API to Responses API#292
pamelafox wants to merge 2 commits intomainfrom
responses-api

Conversation

@pamelafox
Copy link
Copy Markdown
Contributor

Purpose

Migrate the entire application from the OpenAI Chat Completions API to the newer Responses API. This modernizes the codebase to use client.responses.create() instead of client.chat.completions.create(), aligning with OpenAI's recommended API surface going forward.

Key changes:

Backend core (src/backend/fastapi_app/)

  • openai_clients.py: Replace AsyncAzureOpenAI with AsyncOpenAI using base_url="{endpoint}/openai/v1/" for Azure OpenAI. Remove the AZURE_OPENAI_VERSION parameter (no longer needed with the /v1/ endpoint). Remove the GitHub Models host option.
  • dependencies.py: Simplify client creation to use a unified AsyncOpenAI client for both Azure and OpenAI.com, with token-based auth or API key.
  • rag_simple.py / rag_advanced.py: Replace chat.completions.create() calls with responses.create(). Update message format from ChatCompletionMessageParam to ResponseInputItemParam. Update streaming to use Responses API event types.
  • query_rewriter.py: Port query rewriting and search argument extraction to use responses.create() with the new tool call format (ResponseFunctionToolCall).
  • embeddings.py: Switch Azure embed client from AsyncAzureOpenAI to AsyncOpenAI with /v1/ base URL.
  • api_models.py: Remove the seed field from ChatRequestOverrides.
  • prompts/query_fewshots.json: Update few-shot examples to use Responses API message format.

Infrastructure (infra/)

  • Remove AZURE_OPENAI_VERSION from main.bicep and main.parameters.json.
  • Update default chat model to gpt-5.4 with deployment version 2026-03-05.

Evals

  • generate_ground_truth.py: Port to Responses API with updated tool definitions.

Tests

  • Update all mock fixtures in conftest.py to return Responses API objects (Response, ResponseFunctionToolCall, etc.) instead of Chat Completions objects.
  • Simplify test_openai_clients.py to reflect the unified client approach.
  • Update all snapshot JSON/JSONL files in tests/snapshots/ for the new response format.

Config/DevContainer

  • Remove AZURE_OPENAI_VERSION from .env.sample, azure.yaml, and CI workflow.
  • Update openai package version constraint.

Does this introduce a breaking change?

When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
If you're not sure, try it out on an old environment.

[x] Yes
  • AZURE_OPENAI_VERSION environment variable is removed — existing .env files with this variable will still work (it's just ignored), but the Bicep parameter is gone.
  • The seed field is removed from the chat request overrides API.
  • The GitHub Models host (OPENAI_CHAT_HOST=github) is removed.
  • The default chat model changed to gpt-5.4 — existing environments may need to update their model deployment.

Type of change

[x] Refactoring (no functional changes, no api changes)

Code quality checklist

See CONTRIBUTING.md for more details.

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran python -m mypy to check for type errors
  • I either used the pre-commit hooks or ran ruff manually on my code.

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.

1 participant