希望添加openai格式转claude code格式的模型添加方式
希望添加openai格式转claude code格式的模型添加方式
⚠️ Possible Duplicate Issue(s)
📝 Issue Planner
Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.
- [ ] Create Plan
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
💬 Have feedback or questions? Drop into our discord!
Thank you for this feature suggestion.
Current Architecture Analysis:
Claude Code Hub currently enforces strict same-format routing with no cross-format conversion. This is explicitly stated in the README: "严格同格式路由,无跨格式转换".
The format compatibility is enforced in checkFormatProviderTypeCompatibility() at src/app/v1/_lib/proxy/provider-selector.ts (lines 136-154):
function checkFormatProviderTypeCompatibility(
format: ClientFormat,
providerType: Provider["providerType"]
): boolean {
switch (format) {
case "claude":
return providerType === "claude" || providerType === "claude-auth";
case "response":
return providerType === "codex";
case "openai":
return providerType === "openai-compatible";
case "gemini":
return providerType === "gemini";
case "gemini-cli":
return providerType === "gemini-cli";
default:
return true;
}
}
This means a request arriving at /v1/chat/completions (OpenAI format) can only be routed to openai-compatible type providers, and a request at /v1/messages (Claude format) can only go to claude/claude-auth providers. There is no request/response body format conversion between these formats.
Related existing features:
- Model Redirect (
src/app/v1/_lib/proxy/model-redirector.ts): Can remap model names (e.g.,claude-sonnet-4-5togpt-4o), but does not convert the request/response body format. - Format Detection (
src/app/v1/_lib/proxy/format-mapper.ts): Detects whether an incoming request isclaude,openai,response,gemini, orgemini-cliformat, but only for routing purposes.
Related prior request: This is similar to the previously closed issue #304, which suggested adding protocol conversion functionality and referenced Api-Conversion as an example.
Implementation considerations:
Adding cross-format conversion (e.g., OpenAI Chat Completions to/from Claude Messages API) would require:
- Request body converters: Bidirectional translation between OpenAI and Claude message structures (roles, tool calls, system prompts, streaming events, etc.)
- Response body converters: Streaming and non-streaming response format translation
- Modifications to
checkFormatProviderTypeCompatibility: To allow cross-format routing when a converter is available - Modifications to
ProxyForwarder(src/app/v1/_lib/proxy/forwarder.ts): To apply request conversion before forwarding and response conversion on return - Modifications to
ProxyResponseHandler(src/app/v1/_lib/proxy/response-handler.ts): To handle SSE stream format conversion for streaming responses
This is a significant architectural change. The OpenAI and Claude APIs have substantial structural differences in how they handle system prompts, tool definitions, multi-modal content, thinking/reasoning tokens, and streaming events, making complete bidirectional conversion complex.
Automated response from Claude AI
+1
+1
+1 希望4种主流格式能互转
This issue has been automatically marked as stale because it has not had any activity in the last 30 days.
If this issue is still relevant:
- Please comment to keep it open
- Add any new information that might help resolve it
This issue will be automatically closed in 14 days if there is no further activity.
This issue has been automatically closed due to inactivity.
If you believe this issue is still relevant, please feel free to reopen it with additional information.