Skip to content

refactor: collapse four OpenAI-compatible provider clients onto one - #65

Open
KazKozDev wants to merge 1 commit into
mainfrom
refactor/openai-compatible-clients
Open

KazKozDev wants to merge 1 commit into
mainfrom
refactor/openai-compatible-clients

Conversation

@KazKozDev

Copy link
Copy Markdown
Owner

What this changes

openrouter-client.ts, siliconflow-client.ts, deepseek-client.ts and xai-client.ts (about 940 lines of near-identical code) are deleted. chatOpenRouter, chatSiliconFlow, chatDeepSeek and chatXai are now ten-line wrappers in openai-client.ts around chatOpenAICompatible. Their names and signatures are unchanged. Net change: −845 lines.

chatOpenAICompatible gets three options to cover the real differences between the copies:

  • headers: OpenRouter's HTTP-Referer and X-Title attribution headers.
  • passReasoning: echoes reasoning_content on assistant turns, as the four providers' copies did. It is off for OpenAI and for the generic compatible provider, so their behaviour is unchanged.
  • images: false: DeepSeek's API returns 400 on image_url blocks.

Small behaviour changes that come with sharing one function:

  • DeepSeek used plain fetch. It now retries 429 and 5xx responses through fetchWithRetry.
  • All four now get the temperature-400 fallback.
  • xAI now reports thinking when the model returns reasoning.

Why

This is item 1 of the full-code audit. The four copies had already drifted: DeepSeek had no retry, and xAI dropped reasoning. A fix made in one copy did not reach the others.

How it was verified

  • ./scripts/check.sh passes locally
  • Unit tests added or updated for the changed behaviour. New tests cover OpenAI (keeps images, no reasoning echo), OpenRouter (headers and reasoning echo) and DeepSeek (drops images). The existing SiliconFlow retry tests now import from openai-client.

Not run against the live provider APIs.

Checklist

  • One concern per PR — no unrelated refactors bundled in
  • Commit messages follow Conventional Commits

Security-sensitive areas

  • None of the above

🤖 Generated with Claude Code

… shared OpenAI-compatible client

The four client files were near-copies of chatOpenAICompatible. They are now
thin wrappers in openai-client.ts; the shared function gains three options
for the real differences: extra headers (OpenRouter attribution),
passReasoning (echo reasoning_content on assistant turns) and images=false
(DeepSeek rejects image_url blocks).

Side effects: DeepSeek now retries 429/5xx via fetchWithRetry, all four get
the temperature-400 fallback, and xAI streaming now surfaces reasoning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-22T10:16:55.073943Z
We couldn’t complete this review. Comment @codex review to try again.
9097854 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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