Skip to content

feat: add API-key subscription coding plan providers#1240

Closed
guillaumegay13 wants to merge 9 commits intomnfst:mainfrom
guillaumegay13:codex/clean-api-key-subscription-providers
Closed

feat: add API-key subscription coding plan providers#1240
guillaumegay13 wants to merge 9 commits intomnfst:mainfrom
guillaumegay13:codex/clean-api-key-subscription-providers

Conversation

@guillaumegay13
Copy link
Copy Markdown
Collaborator

@guillaumegay13 guillaumegay13 commented Mar 23, 2026

Summary

  • add Z.ai coding-plan subscription support plus opencode, opencode-go, and ollama-cloud providers
  • preserve provider-qualified model identity across discovery/routing for overlapping model IDs
  • fix subscription analytics, billing, and token usage capture for qualified subscription models and streaming usage

Notes for reviewers

Validation

  • npm test --workspace=packages/backend -- --runInBand src/common/constants/providers.spec.ts src/routing/model-discovery/model-discovery.service.spec.ts src/routing/routing.service.spec.ts src/otlp/services/trace-ingest.service.spec.ts src/routing/proxy/__tests__/provider-client.spec.ts src/routing/proxy/__tests__/proxy.controller.spec.ts
  • npm test --workspace=packages/frontend -- --run tests/components/ModelPickerModal.test.tsx tests/pages/Routing.test.tsx tests/components/ProviderKeyForm.test.tsx tests/services/providers.test.ts tests/services/routing-utils.test.ts
  • npm test --workspace=packages/openclaw-plugin -- --runInBand __tests__/hooks.test.ts __tests__/subscription-capabilities.test.ts

Changeset

  • .changeset/add-zai-subscription.md

Impact

  • no migrations

Summary by cubic

Adds API‑key subscription support for coding plans with new providers and tighter routing, billing, and usage tracking. Now includes kimi (Kimi Code), zai, opencode, opencode-go, ollama-cloud, and nano-gpt, with provider‑qualified model IDs preserved end‑to‑end.

  • New Features

    • Added providers: kimi, zai, opencode, opencode-go, ollama-cloud, nano-gpt (subscription‑only where applicable).
    • Routed kimi to an Anthropic‑compatible coding endpoint; routed zai subscription calls to coding‑plan endpoints; curated catalogs (e.g., filtered opencode-go) and qualified provider/model IDs across discovery, routing, and pricing.
    • Normalized usage for streaming and non‑stream responses (input_tokens/output_tokens mapped to OpenAI fields); passthrough streaming usage for deepseek, nano-gpt, ollama, ollama-cloud.
    • UI: added icons; subscription‑only providers shown in Subscriptions (hidden from API Keys); clearer copy and provider shown in Model Picker and Routing.
  • Bug Fixes

    • Qualified nano-gpt subscription model IDs to avoid collisions; improved inference for provider‑qualified IDs.
    • Subscription analytics/billing: dual‑auth providers treated as subscription during rollup (zero cost); fixed SSE handling so trailing zero‑usage chunks don’t overwrite valid usage; improved streaming token capture.
    • Provider filter matches qualified zai/... model IDs; stable provider resolution for duplicate model IDs; prefer cached models to avoid extra discovery; correct endpoint selection for subscription vs API key flows; acquire Postgres row lock before success dedup.

Written for commit 7208299. Summary will update on new commits.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 98.43137% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.55%. Comparing base (2ca4353) to head (7208299).
⚠️ Report is 662 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1240      +/-   ##
==========================================
+ Coverage   98.47%   98.55%   +0.08%     
==========================================
  Files          92       94       +2     
  Lines        7528     7745     +217     
  Branches     2878     2929      +51     
==========================================
+ Hits         7413     7633     +220     
- Misses         88       90       +2     
+ Partials       27       22       -5     
Flag Coverage Δ
frontend 98.72% <98.72%> (+<0.01%) ⬆️
plugin 96.84% <97.95%> (+0.95%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 23, 2026

Bundle Report

Changes will increase total bundle size by 7.89kB (1.53%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
manifest-frontend-esm 524.14kB 7.89kB (1.53%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: manifest-frontend-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-*.css 2.81kB 114.66kB 2.52%
assets/Routing-*.js 225 bytes 82.93kB 0.27%
assets/index-*.js 1.96kB 35.91kB 5.79% ⚠️
assets/ProviderIcon-*.js 2.69kB 27.74kB 10.73% ⚠️
assets/provider-*.js 203 bytes 986 bytes 25.93% ⚠️

Files in assets/Routing-*.js:

  • ./src/components/ModelPickerModal.tsx → Total Size: 15.13kB

  • ./src/components/ProviderSelectModal.tsx → Total Size: 10.83kB

  • ./src/components/ProviderDetailView.tsx → Total Size: 12.63kB

  • ./src/components/ProviderKeyForm.tsx → Total Size: 10.48kB

Files in assets/ProviderIcon-*.js:

  • ./src/components/ProviderIcon.tsx → Total Size: 22.03kB

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 48 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/openclaw-plugin/subscription-capabilities/index.js">

<violation number="1" location="packages/openclaw-plugin/subscription-capabilities/index.js:79">
P2: Z.ai’s model IDs overlap with other subscription providers (e.g., `glm-5`), but this config omits `alwaysQualifyModelIds`. That leaves Z.ai models unqualified in `qualifyDiscoveredModelId`, so overlapping IDs can collide and route to the wrong provider. Add `alwaysQualifyModelIds: true` for Z.ai.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread packages/openclaw-plugin/subscription-capabilities/index.js
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 48 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/backend/src/common/utils/provider-inference.ts">

<violation number="1" location="packages/backend/src/common/utils/provider-inference.ts:5">
P1: `zai/` qualified models are not handled in the new internal prefix map, so they fall through to the generic `vendor/model -> openrouter` rule and can resolve to the wrong provider.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread packages/backend/src/common/utils/provider-inference.ts
@guillaumegay13
Copy link
Copy Markdown
Collaborator Author

One additional change in this PR is Kimi Code subscription support.

This adds a dedicated kimi subscription provider, separate from Moonshot Open Platform, because the coding-plan API behaves differently:

  • model discovery uses GET https://api.kimi.com/coding/v1/models
  • request routing uses the Anthropic-compatible POST /v1/messages path
  • the current coding-plan catalog intentionally exposes a single public model, kimi-for-coding

That is why the subscription manifests, backend routing/discovery, and frontend provider list now include kimi as its own subscription provider instead of treating it as another Moonshot model variant.

- Register nano-gpt in subscription-capabilities, provider registry,
  endpoints, model fetcher, and frontend provider definitions
- Add inline SVG icon in ProviderIcon.tsx
- Add nano-gpt to INTERNAL_PROVIDER_PREFIX_MAP (backend + frontend)
  so model names like nano-gpt/vendor/model resolve correctly
- Add nano-gpt to STREAM_USAGE_PROVIDERS so streaming responses
  include token usage via stream_options
- Prevent zero-usage final SSE chunks from overwriting valid captured
  usage in pipeStream (fixes NanoGPT token reporting)
@guillaumegay13
Copy link
Copy Markdown
Collaborator Author

Added NanoGPT (https://nano-gpt.com/api) as it was requested by the community too.

It's a subscription with an API key - similar to all the providers added in this PR. It serves a lot of models!

@SebConejo SebConejo self-requested a review March 26, 2026 22:57
Copy link
Copy Markdown
Member

@SebConejo SebConejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the PR! I can't merge this as-is:

  1. API-key providers don't belong in Subscriptions. Connecnting ot the new providers from subscription tabs, suggest me to use standard API keys. We should use the subsctipion way.
  2. Kimi and Z.ai already exist (Moonshot provider -> Kimi).
  3. OpenCode-Go should not be here. they're other agents (alternative to OpenClaw). The vision is to support other agents besides OpenClaw in the future, not to route through as LLM providers.
  4. Adding 6 providers in a single PR makes review and
    testing very wide. Each new provider (especially with OAuth) is a significant release on its own. Could we have 1 PR per provider instead?

@guillaumegay13
Copy link
Copy Markdown
Collaborator Author

Hey @SebConejo

API-key providers don't belong in Subscriptions
=> they are subscriptions - but they use API keys to authenticate and not OAuth

Kimi and Z.ai already exist (Moonshot provider -> Kimi)
=> yes in the API key pay-per-use, not subscription plans

OpenCode-Go should not be here. they're other agents (alternative to OpenClaw). The vision is to support other agents besides OpenClaw in the future, not to route through as LLM providers.
=> OpenCode Go is a subscription for OpenCode models & has been requested by the community

Adding 6 providers in a single PR makes review and testing very wide. Each new provider (especially with OAuth) is a significant release on its own. Could we have 1 PR per provider instead?
=> OK, I grouped them because they are all subscription providers using API keys for auth, so there are shared code and patterns

@guillaumegay13 guillaumegay13 deleted the codex/clean-api-key-subscription-providers branch April 23, 2026 12:15
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.

2 participants