Skip to content

feat: add OpenAI Responses API adapter support#7

Open
x5iu wants to merge 7 commits intomainfrom
feat/openai-response-api
Open

feat: add OpenAI Responses API adapter support#7
x5iu wants to merge 7 commits intomainfrom
feat/openai-response-api

Conversation

@x5iu
Copy link
Copy Markdown
Owner

@x5iu x5iu commented Nov 27, 2025

Summary

  • Add OpenAI Responses API provider integration alongside Anthropic and OpenRouter
  • Implement full request/response conversion between Anthropic Messages API and OpenAI Responses API
  • Support streaming responses with proper event mapping
  • Add OpenAI provider configuration in profile system

Changes

  • Request Conversion (pkg/adapter/convert_request.go):

    • Convert Anthropic messages to OpenAI input items
    • Convert tools and tool_choice to function format
    • Support thinking/reasoning configuration
    • Handle tool results and function call responses
  • Stream Conversion (pkg/adapter/convert_stream.go):

    • Convert OpenAI streaming events to Anthropic event format
    • Handle text deltas, reasoning deltas, function calls
    • Support ResponseBuilder for collecting full response
  • Profile Configuration (pkg/profile/):

    • Add OpenAIConfig with base_url and api_key
    • Update profile loading to include OpenAI config
    • Add getter methods for safe config access
  • Server Integration (cmd/claude-code-adapter-cli/serve.go):

    • Add ProviderOpenAI constant
    • Route requests to OpenAI Responses API when profile.provider == "openai"
  • Snapshot Support (pkg/snapshot/):

    • Add OpenAIRequest and OpenAIResponse fields
    • Add OpenAIConfig to snapshot config

Test plan

  • Test with OpenAI API key configured
  • Verify request conversion for various message types
  • Verify streaming response conversion
  • Test function/tool call flows

🤖 Generated with Claude Code

x5iu and others added 7 commits December 28, 2025 23:09
- Add OpenAI Responses API provider integration alongside Anthropic and OpenRouter
- Implement ConvertAnthropicRequestToOpenAIRequest for request conversion
  - Convert messages, tools, tool_choice to OpenAI format
  - Support thinking/reasoning configuration
  - Handle tool results and function call responses
- Implement ConvertOpenAIStreamToAnthropicStream for stream conversion
  - Convert streaming events to Anthropic event format
  - Handle text deltas, reasoning deltas, function calls
  - Support ResponseBuilder for collecting full response
- Add OpenAI provider configuration support in profile system
  - Add OpenAIConfig with base_url and api_key
  - Update profile loading to include OpenAI config
  - Add getter methods for safe config access
- Integrate OpenAI provider routing in serve.go
  - Add ProviderOpenAI constant
  - Route requests to OpenAI Responses API when profile.provider == "openai"
- Add snapshot support for OpenAI requests/responses
- Fix provider.go endpoint path from /responses to /v1/responses

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Use a type alias inside the UnmarshalJSON method to avoid calling the
same method recursively when unmarshaling JSON arrays.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add TestCreateOpenAIModelResponse_Basic for basic streaming test
- Add TestCreateOpenAIModelResponse_DataFormat for response structure validation
- Add TestCreateOpenAIModelResponse_WithReasoning for o3-mini reasoning test
- Add TestCreateOpenAIModelResponse_FunctionCalls for tool calling test
- Add validateOpenAIEvent and validateOpenAIResponse helper functions
- Fix ResponseReasoningItem.Summary to use array type instead of pointer
- Fix provider.go template to include .ctx for OpenAI api_key config

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add OPENAI_BASE_URL and OPENAI_API_KEY to CI environment to enable
OpenAI Response API tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…ng images

When converting Anthropic system messages to OpenAI format:
- If all system content is text, use the `instructions` field
- If system content contains images or other non-text content, convert to
  an input message with `system` role

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add tests verifying the Anthropic to OpenAI system message conversion:
- Text-only system messages convert to instructions field
- System messages with images convert to input with system role
- Empty and nil system messages are handled correctly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@x5iu x5iu force-pushed the feat/openai-response-api branch from 6b1ece6 to 693ab2d Compare December 28, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

opus-4.5 This PR is generated by opus 4.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant