Skip to content

feat: add API key mode for WorkBuddy international accounts - #6

Closed
leonid-dalin wants to merge 16 commits into
HanHan666666:mainfrom
leonid-dalin:direct-key-mode
Closed

leonid-dalin wants to merge 16 commits into
HanHan666666:mainfrom
leonid-dalin:direct-key-mode

Conversation

@leonid-dalin

Copy link
Copy Markdown

Why

WorkBuddy international accounts (Keycloak realm on www.workbuddy.ai) get 401s from the desktop-token path: the token does not match the backend the converter calls, and the refresh endpoint rejects it with invalid_grant. The result is that international subscribers cannot use the converter at all.

What this changes

New --direct-key mode (also via CODEBUDDY_DIRECT_KEY):

  • Skips the desktop session entirely. A CK_* API key (generated at codebuddy.ai/profile/keys, the same key the CLI documents as CODEBUDDY_API_KEY) is sent as a plain Authorization: Bearer header to https://www.codebuddy.ai/v2/chat/completions.
  • /v1/models becomes realm-aware: the desktop-token path keeps the existing China catalog unchanged; the key mode serves the international catalog.
  • The startup preflight, which expects a desktop session, is skipped in key mode.
  • Headless deployment (servers, containers, NAS) now works, since nothing depends on a logged-in desktop app.

Model list (fixes the international half of #4)

All 16 ids below answered 200 on 2026-08-31 against the international endpoint:

auto, hy3, glm-5.3, glm-5.2, glm-5.1, glm-5v-turbo, minimax-m3, kimi-k3, kimi-k2.7, kimi-k2.6, deepseek-v4-pro, deepseek-v4-flash, gpt-5.6-luna, gpt-5.6-terra, gpt-5.6-sol, gemini-3.1-pro

(gpt-5.6-* and gemini-3.1-pro go beyond #4's CLI list; they are part of the international subscription and work over this endpoint.)

Upstream quirks documented in the README (EN + ZH)

  • Requests must use stream: true (error 11101); the converter already streams upstream and aggregates.
  • The first message must have role system (error 11128); the converter prepends one when missing.
  • Model IDs are case-sensitive (error 11102): hy3 works, Hy3 does not.
  • The gpt-5.6 family rejects small max_tokens values (error 11133); roughly 100 is a safe floor.

Compatibility

Every new branch is gated behind CONFIG["direct_key"]. Without the flag, credential loading, preflight, headers, and the model list behave exactly as before. Tested by starting the converter without the flag and comparing /health and /v1/models output against upstream.

Function calling (tool_calls), streaming and non-streaming aggregation were verified end to end through the proxy in key mode.

Closes #4 partially: the international model list; the maintainers may want to keep or replace the hardcoded China list separately (the issue's option two, parsing CLI --help, remains a good idea).

Docs updated in English and Chinese. No credentials are included in this PR.

DALIN and others added 9 commits August 31, 2026 03:55
The desktop-token path 401s for www.workbuddy.ai (Keycloak) accounts:
the token does not match the backend and refresh fails with
invalid_grant. Skip the desktop session entirely and call the
international endpoint with a CK_* API key, which also enables
headless deployment. In this mode /v1/models serves the
international catalog and the desktop preflight is skipped.

Closes #4 (international model list half; CN list unchanged)
Unit tests cover backend domain mapping, both model catalogs,
credential loading and expiry, client authentication including the
open-access mode, and the direct-key guard on the credential path.

Endpoint tests exercise /health, /v1/models in both realms and the
chat endpoint against a fake upstream: bearer header construction,
system message handling, forced upstream streaming with non-stream
aggregation, SSE passthrough and upstream connection errors.

Run with: pytest
The README asked for a hand-typed pip install line, which drifts and
misses test dependencies. Pin the runtime set in requirements.txt and
the test set in requirements-dev.txt, and point the install and test
instructions at them.
@leonid-dalin

Copy link
Copy Markdown
Author

maintaining this as a standalone fork; no longer seeking a merge

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.

/v1/models 返回的模型列表过时,与 WorkBuddy 桌面端/CLI 不一致

1 participant