Skip to content

feat(provider): add CodeBuddy international provider (www.codebuddy.ai)#1845

Open
Yanu403 wants to merge 1 commit into
decolua:masterfrom
Yanu403:feat/codebuddy-provider
Open

feat(provider): add CodeBuddy international provider (www.codebuddy.ai)#1845
Yanu403 wants to merge 1 commit into
decolua:masterfrom
Yanu403:feat/codebuddy-provider

Conversation

@Yanu403

@Yanu403 Yanu403 commented Jun 16, 2026

Copy link
Copy Markdown

Summary

Adds CodeBuddy (www.codebuddy.ai) as a fully functional provider with API key authentication, enabling users to access GPT-5.5, GPT-5.4, Claude Sonnet 4.6, and Gemini 3.1 Pro through their CodeBuddy subscriptions.

The existing codebuddy.js registry entry was hidden: true and pointed to copilot.tencent.com (China-only). This PR switches it to the international domain, adds models, and exposes it to users.

Changes

1. Registry (providers/registry/codebuddy.js)

  • Switch baseUrl from copilot.tencent.com to www.codebuddy.ai/v2/chat/completions
  • Change category from oauth to apikey (API key is the primary auth method)
  • Add forceStream: true (server requires streaming — rejects non-stream with error 11101)
  • Add 4 confirmed-working models: gpt-5.5, gpt-5.4, claude-sonnet-4.6, gemini-3.1-pro
  • Set hidden: false to expose to users
  • Keep OAuth config for future device flow support

2. Executor (executors/codebuddy.js)

Lightweight shim over DefaultExecutor (~53 LOC). Two responsibilities:

  • System message injection: CodeBuddy's API requires a system message in the messages array (returns 11101:invalid request without one). Injects You are a helpful assistant. when absent.
  • Dual-header auth: Sends both Authorization: Bearer and X-API-Key with the same token, matching the CLI's fingerprint.

3. Executor registration (executors/index.js)

Import and register CodeBuddyExecutor in the executor map.

API Wire Format

Captured via mitmproxy interception of codebuddy -p CLI v2.106.3:

Request:

POST https://www.codebuddy.ai/v2/chat/completions
Authorization: Bearer ck_<id>.<secret>
Content-Type: application/json

{
  "model": "gpt-5.5",
  "messages": [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello"}
  ],
  "stream": true
}

Response (SSE):

data: {"id":"resp_...","model":"gpt-5.5","object":"response","choices":[{"delta":{"content":"Hi"}}]}

data: {"id":"resp_...","choices":[{"delta":{"content":""},"finish_reason":"stop"}],"usage":{"total_tokens":42}}

data: [DONE]

Testing

  • ✅ Syntax validation (Node.js ESM import check)
  • ✅ Unit tests: system message injection (4/4 pass — inject, no-duplicate, empty-messages, headers)
  • ✅ Live smoke test: real API call through executor → HTTP 200 → reconstructed "PONG"
  • ✅ Verified with ck_* API key from active CodeBuddy account

API Key Setup

Users obtain API keys from: https://www.codebuddy.ai/console/api-keys

Key format: ck_<id>.<secret>

Add as API key connection in 9router dashboard → Providers → CodeBuddy.

Constraints (documented in executor JSDoc)

  1. System message required: Server returns {"code":11101,"msg":"Parse message failed: 11101:invalid request"} without it. Handled by ensureSystemMessage() in the executor.
  2. Stream-only: stream: false returns {"code":11101,"msg":"Non-stream chat request is currently not supported"}. Handled by forceStream: true in registry.

Not in scope (future PRs)

  • Device flow OAuth (/v2/plugin/auth/state + /v2/plugin/auth/token)
  • Live model discovery via dashboard API
  • Tool calling validation (presumably zero-effort since OpenAI format, not yet tested)
  • Vision/image input support

Closes #

- Update registry/codebuddy.js: switch baseUrl from copilot.tencent.com
  to www.codebuddy.ai/v2/chat/completions, add forceStream:true,
  add 4 confirmed models (gpt-5.5, gpt-5.4, claude-sonnet-4.6,
  gemini-3.1-pro), set category to apikey, expose to UI.

- Add executors/codebuddy.js: thin shim over DefaultExecutor that
  injects an empty system message when absent (server returns 11101
  without one) and adds X-API-Key header matching CLI fingerprint.

- Register executor in executors/index.js.

Wire-tested via mitmproxy capture + direct curl replay against live
ck_* API keys. SSE streaming confirmed with OpenAI-compatible
[data: {...}] + data: [DONE] envelope.
bloodf pushed a commit to bloodf/9router that referenced this pull request Jun 19, 2026
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