Skip to content

feat(models): add Baidu Qianfan International - #3571

Merged
steebchen merged 9 commits into
mainfrom
tyler-v2
Aug 18, 2026
Merged

steebchen merged 9 commits into
mainfrom
tyler-v2

Conversation

@steebchen

@steebchen steebchen commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

Baidu Qianfan International serves several third-party models behind an OpenAI-compatible API, but the gateway could not route to it. This adds baidu as an international-only provider at https://api.baiduqianfan.ai/v1.

Active models and pricing

The catalogue uses standard public pay-as-you-go prices. It does not encode promotional, off-peak, account-effective, or negotiated discounts.

Model External ID Input Cached Output Context Max output
DeepSeek V4 Pro deepseek-v4-pro $1.69 $0.14 $3.38 1048576 131072
DeepSeek V4 Flash deepseek-v4-flash $0.14 $0.028 $0.28 1048576 131072
GLM-5 glm-5 $1.00 $0.20 $3.20 202752 131072
GLM-5.1 glm-5.1 $1.40 $0.26 $4.40 202752 131072
GLM-5.2 glm-5.2 $1.40 $0.26 $4.40 1048576 131072
Kimi K2.6 kimi-k2.6 $0.95 $0.16 $4.00 262144 262144

Prices are USD per million tokens and follow Qianfan International's public rate card.

Qianfan rejects deepseek-v3.2-intl, hy3, and mimo-v2.5 with invalid_model. Those mappings were introduced only on this unmerged branch, so they are removed entirely. AGENTS.md now clarifies that the no-removal rule applies only to definitions already present on origin/main.

Integration details

  • Adds provider metadata, API-key configuration, Helm and e2e wiring, and the provider icon.
  • Uses standard bearer authentication and /v1/chat/completions.
  • Prevents reasoning-token double billing: Qianfan reports reasoning tokens separately while already including them in completion_tokens.
  • Declares none, minimal, low, medium, high, xhigh, and max reasoning efforts for all six models. Qianfan requires thinking: { type: "disabled" } to reliably implement none.
  • Maps tools, reasoning, vision, and structured output conservatively from provider metadata. GLM-5 JSON output stays disabled because Qianfan's API and model page conflict.
  • Keeps DeepSeek V4 Pro's advertised output limit at the lower documented 131072-token bound.

ERNIE 5.0 is omitted because the authenticated international catalogue does not list it. The dated deepseek-v4-flash-0731 alias and qianfan-ocr-fast are also omitted rather than duplicating an existing model or guessing missing capability metadata.

Verification

  • pnpm format — passed
  • pnpm build — 17/17 tasks passed
  • Model metadata and cost tests — 142/142 passed
  • Live reasoning probe — all seven declared efforts returned 200 on all six mappings; an invalid effort returned 400 on all six; the separate disable switch returned no reasoning content on all six
  • Scoped e2e with TEST_MODELS="baidu/deepseek-v4-pro,baidu/deepseek-v4-flash,baidu/glm-5,baidu/glm-5.1,baidu/glm-5.2,baidu/kimi-k2.6" CONCURRENT_TESTS=false FULL_MODE=true pnpm test:e2e — 29 files passed, 193 tests passed, 99 non-applicable tests skipped
  • The scoped e2e includes all 42 model/effort combinations plus basic and streaming chat, reasoning, JSON output where supported, tool calls, tool-result continuation, and combined reasoning with tools.

Adds Baidu as a provider backed by the Qianfan platform, whose
OpenAI-compatible surface lives at /v2/chat/completions rather than /v1.

Covers the eight language models Qianfan offers on the Hong Kong
pay-as-you-go plan: ERNIE 5.0 as a new model definition, plus provider
mappings for DeepSeek V3.2 / V4 Pro / V4 Flash, GLM-5 / 5.1 / 5.2 and
Kimi K2.6. Context and output limits come from Qianfan's own /v2/models
catalogue.

Qianfan counts reasoning inside completion_tokens while also reporting
it under completion_tokens_details, so it joins the
completionIncludesReasoning set - without that, a thinking reply bills
its output twice.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 12, 2026 15:14
@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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0302bd7b-ec44-479e-8c36-245fa3ae0525

📥 Commits

Reviewing files that changed from the base of the PR and between c0dc241 and 8e1028d.

📒 Files selected for processing (4)
  • apps/gateway/src/chat/tools/transform-streaming-to-openai.ts
  • infra/helm/llmgateway/values.yaml
  • packages/models/src/models/deepseek.ts
  • packages/models/src/models/zai.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/gateway/src/chat/tools/transform-streaming-to-openai.ts
  • infra/helm/llmgateway/values.yaml
  • packages/models/src/models/deepseek.ts
  • packages/models/src/models/zai.ts

Walkthrough

The change adds Baidu Qianfan as a provider with API-key configuration, model mappings, endpoint routing, streaming support, cost handling, e2e wiring, and UI branding.

Changes

Baidu provider support

Layer / File(s) Summary
Provider and model catalog
packages/models/src/providers.ts, packages/models/src/models/*, apps/gateway/src/models/models.spec.ts
The catalog adds Baidu metadata and mappings for DeepSeek, Kimi, Hy3, Xiaomi, and GLM models. The max-output regression test now covers an active kimi-k2 mapping.
Endpoint, streaming, and billing flow
packages/actions/src/get-provider-endpoint.ts, apps/gateway/src/chat/tools/transform-streaming-to-openai.ts, apps/gateway/src/lib/costs.ts, apps/gateway/src/lib/costs.spec.ts
Baidu uses its default Qianfan URL and /v1/chat/completions. Shared streaming conversion handles Baidu responses. Reasoning tokens are not billed twice.
Configuration and provider presentation
.env.example, .env.unified.example, .github/workflows/e2e.yml, infra/helm/llmgateway/values.yaml, packages/shared/src/components/provider-icons.tsx, apps/ui/src/components/provider-keys/provider-logo.ts
Baidu API-key settings are added to local, unified, Helm, and e2e configuration. Baidu logo rendering and lookup are registered.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8e102

This PR adds the Baidu Qianfan International provider and its model, pricing, capability, and token-accounting mappings. No actionable merge-blocking risk remains beyond normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Gateway
  participant EndpointResolver
  participant BaiduQianfan
  Client->>Gateway: Send chat completion request
  Gateway->>EndpointResolver: Resolve Baidu endpoint
  EndpointResolver->>BaiduQianfan: POST /v1/chat/completions
  BaiduQianfan-->>Gateway: Return streaming response
  Gateway-->>Client: Return OpenAI-compatible stream
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding the Baidu Qianfan International provider and its models.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tyler-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/actions/src/get-provider-endpoint.ts (1)

956-958: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add Qianfan endpoint unit coverage.

Assert the default and caller-supplied Baidu base URLs both use /v2/chat/completions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/actions/src/get-provider-endpoint.ts` around lines 956 - 958, Add
unit coverage for the Baidu branch in the provider endpoint tests, asserting
both the default base URL and a caller-supplied base URL resolve to
/v2/chat/completions. Reuse the existing endpoint test patterns and fixtures.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/models/src/models/baidu.ts`:
- Around line 20-28: Update the Qianfan capability mappings: in
packages/models/src/models/baidu.ts lines 20-28, set the vision flag to false;
in packages/models/src/models/moonshot.ts lines 566-582, set vision to false and
remove the supportedToolChoices restriction. Keep the remaining capability flags
unchanged until funded endpoint testing verifies these behaviors.

---

Nitpick comments:
In `@packages/actions/src/get-provider-endpoint.ts`:
- Around line 956-958: Add unit coverage for the Baidu branch in the provider
endpoint tests, asserting both the default base URL and a caller-supplied base
URL resolve to /v2/chat/completions. Reuse the existing endpoint test patterns
and fixtures.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 51702889-166f-4bc8-bd53-ac8a7a4378d7

📥 Commits

Reviewing files that changed from the base of the PR and between 92b6cf7 and 143119e.

📒 Files selected for processing (17)
  • .env.example
  • .env.unified.example
  • .github/workflows/e2e.yml
  • apps/gateway/src/chat/tools/transform-streaming-to-openai.ts
  • apps/gateway/src/lib/costs.spec.ts
  • apps/gateway/src/lib/costs.ts
  • apps/gateway/src/models/models.spec.ts
  • apps/ui/src/components/provider-keys/provider-logo.ts
  • infra/helm/llmgateway/values.yaml
  • packages/actions/src/get-provider-endpoint.ts
  • packages/models/src/models.ts
  • packages/models/src/models/baidu.ts
  • packages/models/src/models/deepseek.ts
  • packages/models/src/models/moonshot.ts
  • packages/models/src/models/zai.ts
  • packages/models/src/providers.ts
  • packages/shared/src/components/provider-icons.tsx

Comment thread packages/models/src/models/baidu.ts
steebchen and others added 2 commits August 13, 2026 15:17
# Conflicts:
#	packages/models/src/models/baidu.ts
Repoints the Baidu provider at Qianfan International
(https://api.baiduqianfan.ai/v1) and drops the mainland surface. That
endpoint publishes its catalogue in USD, so every mapping is now taken
from it directly rather than from a price sheet.

Corrections that fell out of it: DeepSeek V3.2 is served as
`deepseek-v3.2-intl`; GLM-5 is $0.70/$0.14/$2.24, not $1.00/$0.20/$3.20;
and several context and output limits were too generous. ERNIE 5.0 is
not offered internationally, so its definition is removed - the file
keeps only the Novita ERNIE 4.5 VL entry from main.

Adds mappings for the two remaining international chat models the
catalogue already carries, Hy3 and MiMo V2.5, and turns on jsonOutput
now that the API declares structured_outputs on every chat model.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@steebchen steebchen changed the title feat(models): add Baidu Qianfan provider feat(models): add Baidu Qianfan International Aug 13, 2026
steebchen and others added 4 commits August 13, 2026 19:49
Qianfan's published price list and the sheet we were quoted both put
GLM-5 at $1.00/$0.20/$3.20, while /v1/models reports exactly 70% of
that. The API appears to serve account-effective rather than list
pricing, and a negotiated discount does not belong in the catalogue,
so the list price goes back in.

Also drops jsonOutput on GLM-5, where Qianfan's model page contradicts
the API and lists structured output as unsupported, and caps DeepSeek
V4 Pro output at the lower of the two figures the two sources give.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@steebchen
steebchen merged commit e2e9c1f into main Aug 18, 2026
31 of 32 checks passed
@steebchen
steebchen deleted the tyler-v2 branch August 18, 2026 10:14
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