claude-code-hub icon indicating copy to clipboard operation
claude-code-hub copied to clipboard

希望添加openai格式转claude code格式的模型添加方式

Open shadow9528 opened this issue 7 months ago • 7 comments

希望添加openai格式转claude code格式的模型添加方式

shadow9528 avatar Apr 06 '26 14:04 shadow9528

⚠️ Possible Duplicate Issue(s)
  • https://github.com/ding113/claude-code-hub/issues/304

📝 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!

coderabbitai[bot] avatar Apr 06 '26 14:04 coderabbitai[bot]

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-5 to gpt-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 is claude, openai, response, gemini, or gemini-cli format, 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:

  1. Request body converters: Bidirectional translation between OpenAI and Claude message structures (roles, tool calls, system prompts, streaming events, etc.)
  2. Response body converters: Streaming and non-streaming response format translation
  3. Modifications to checkFormatProviderTypeCompatibility: To allow cross-format routing when a converter is available
  4. Modifications to ProxyForwarder (src/app/v1/_lib/proxy/forwarder.ts): To apply request conversion before forwarding and response conversion on return
  5. 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

github-actions[bot] avatar Apr 06 '26 14:04 github-actions[bot]

+1

jjj124 avatar Apr 14 '26 16:04 jjj124

+1

hitechr avatar May 03 '26 13:05 hitechr

+1 希望4种主流格式能互转

htoday avatar May 05 '26 14:05 htoday

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.

github-actions[bot] avatar Jun 05 '26 02:06 github-actions[bot]

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.

github-actions[bot] avatar Jun 17 '26 02:06 github-actions[bot]