Conversation
Add new Z AI provider to the platform with corresponding models: GLM-4.5, GLM-4.5 Air, GLM-4.5 X, GLM-4.5 AirX, GLM-4.5 Flash, and GLM-4 32B (0414-128k). Integrate API key handling, provider logic, and API endpoint configurations to support Z AI models.
WalkthroughSupport for the "Z AI" provider is added throughout the codebase. This includes registering the provider and its models, updating API key and environment variable mappings, integrating the provider into API request handling, and exposing its metadata. The GitHub Actions workflow is updated to pass the new secret API key for "Z AI". UI components are enhanced with a new icon and layout adjustments to support the provider's branding. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Gateway
participant ProviderAPI
participant ZAI_API
Client->>Gateway: Request model completion (provider: "zai")
Gateway->>ProviderAPI: Prepare headers, body, endpoint for "zai"
ProviderAPI->>ZAI_API: POST /api/paas/v4/chat/completions with Bearer token
ZAI_API-->>ProviderAPI: Response (streaming or JSON)
ProviderAPI-->>Gateway: Forward response
Gateway-->>Client: Return result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (2)
🧰 Additional context used📓 Path-based instructions (3)**/*.{js,jsx,ts,tsx}📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Files:
apps/ui/**/*.{js,jsx,ts,tsx}📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)
Files:
🧬 Code Graph Analysis (1)apps/ui/src/components/ui/providers-icons.tsx (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (2)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/models/src/models/zai.ts (3)
3-142: Avoid hand-written repetition – generate the six variants programmaticallyVirtually every property other than
id,name, and (implicitly)modelNameis identical across the six objects. Manually duplicating them invites drift when a price, flag, or context size needs to change later.A tiny helper eliminates the duplication and keeps the model catalogue easy to maintain:
-export const zaiModels = [ - { - id: "glm-4.5", - name: "GLM-4.5", - family: "glm", - ... - }, - // 5 more copies… -] as const satisfies ModelDefinition[]; +const COMMON_PROVIDER_FIELDS = { + providerId: "zai", + inputPrice: 0.11 / 1e6, + outputPrice: 0.28 / 1e6, + requestPrice: 0, + contextSize: 128_000, + maxOutput: undefined, + streaming: true, + vision: false, + tools: true, + test: "only", +} as const; + +const VARIANTS = [ + { id: "glm-4.5", name: "GLM-4.5" }, + { id: "glm-4.5-air", name: "GLM-4.5 Air" }, + { id: "glm-4.5-x", name: "GLM-4.5 X" }, + { id: "glm-4.5-airx", name: "GLM-4.5 AirX" }, + { id: "glm-4.5-flash", name: "GLM-4.5 Flash" }, + { id: "glm-4-32b-0414-128k",name: "GLM-4 32B (0414-128k)" }, +] as const; + +export const zaiModels = VARIANTS.map(({ id, name }) => ({ + id, + name, + family: "glm", + providers: [ + { ...COMMON_PROVIDER_FIELDS, modelName: id }, + ], + jsonOutput: true, +})) as const satisfies ModelDefinition[];This trims ~120 duplicated lines while preserving type safety.
14-16: Name the per-token price constants for readabilityThe
0.11 / 1e6and0.28 / 1e6literals obscure intent at a glance. Extracting them once makes the units obvious:- inputPrice: 0.11 / 1e6, - outputPrice: 0.28 / 1e6, + const TOKENS_PER_MILLION = 1_000_000; + const INPUT_PRICE_USD_PER_TOKEN = 0.11 / TOKENS_PER_MILLION; + const OUTPUT_PRICE_USD_PER_TOKEN = 0.28 / TOKENS_PER_MILLION; + + inputPrice: INPUT_PRICE_USD_PER_TOKEN, + outputPrice: OUTPUT_PRICE_USD_PER_TOKEN,Minor, but it prevents accidental mis-scaling when future prices change.
Also applies to: 37-39, 60-62, 83-85, 106-108, 129-131
8-9: Omit explicitundefinedfields to reduce noiseProperties set to
undefinedcan simply be left out—their absence conveys the same meaning while shortening each object.Example:
- deprecatedAt: undefined, - deactivatedAt: undefined, + // no deprecation / deactivationSame applies to
maxOutput: undefined.Also applies to: 18-19, 31-32, 40-41, 54-55, 63-64, 77-78, 86-87, 100-101, 109-110, 123-124, 132-133
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.github/workflows/run.yml(1 hunks)apps/gateway/src/lib/provider.ts(1 hunks)packages/models/src/models.ts(2 hunks)packages/models/src/models/zai.ts(1 hunks)packages/models/src/provider-api.ts(4 hunks)packages/models/src/providers.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
Use localStorage instead of cookies for client-side data persistence
Files:
apps/gateway/src/lib/provider.tspackages/models/src/models.tspackages/models/src/provider-api.tspackages/models/src/providers.tspackages/models/src/models/zai.ts
**/*.{js,ts}
📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
**/*.{js,ts}: Use drizzle with the latest object syntax for database operations
For read queries, always usedb().query.<table>.findMany()ordb().query.<table>.findFirst()
Files:
apps/gateway/src/lib/provider.tspackages/models/src/models.tspackages/models/src/provider-api.tspackages/models/src/providers.tspackages/models/src/models/zai.ts
{apps/api,apps/gateway,packages/db}/**/*.ts
📄 CodeRabbit Inference Engine (CLAUDE.md)
{apps/api,apps/gateway,packages/db}/**/*.ts: Use Drizzle ORM with latest object syntax for database operations
For reads, usedb().query.<table>.findMany()ordb().query.<table>.findFirst()
Files:
apps/gateway/src/lib/provider.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)
Never use
as anyor: anyin TypeScript files.
Files:
apps/gateway/src/lib/provider.tspackages/models/src/models.tspackages/models/src/provider-api.tspackages/models/src/providers.tspackages/models/src/models/zai.ts
🧠 Learnings (1)
📚 Learning: the correct base url for nebius ai api is "https://api.studio.nebius.com" (not "https://api.studio.n...
Learnt from: steebchen
PR: theopenco/llmgateway#555
File: packages/models/src/provider-api.ts:300-302
Timestamp: 2025-07-31T00:39:52.691Z
Learning: The correct base URL for Nebius AI API is "https://api.studio.nebius.com" (not "https://api.studio.nebius.ai" as some documentation might suggest).
Applied to files:
packages/models/src/provider-api.ts
🧬 Code Graph Analysis (2)
packages/models/src/models.ts (1)
packages/models/src/models/zai.ts (1)
zaiModels(3-142)
packages/models/src/models/zai.ts (1)
packages/models/src/models.ts (1)
ModelDefinition(75-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build / run
🔇 Additional comments (8)
apps/gateway/src/lib/provider.ts (1)
21-22:zai→Z_AI_API_KEYmapping looks correct
The new provider ID is wired to its env-var consistently with the existing naming scheme. No further action needed..github/workflows/run.yml (1)
56-57: Make sure the secret actually exists in the repository / org settings
Z_AI_API_KEYis injected here, but the workflow will fail if the secret hasn’t been added under Settings → Secrets and Variables.
Please double-check before merging.packages/models/src/models.ts (1)
14-15: Models list extended correctly
ImportingzaiModelsand spreading them into the master array keeps type-safety and ordering intact. Looks good.Also applies to: 120-121
packages/models/src/providers.ts (1)
213-223: Provider definition is complete
All mandatory metadata flags are present (streaming,cancellation,jsonOutput,color,website). No issues spotted.packages/models/src/provider-api.ts (3)
31-36: Header handling – OK
Treating Z AI like the OpenAI-compatible providers (Bearer token only) is reasonable given the public docs. No concerns here.
83-113: Confirm request-body parity with OpenAI spec
stream_options,response_format, andreasoning_effortare forwarded to Z AI. Verify that Z AI’s API accepts these OpenAI-specific fields; otherwise calls may reject with 4xx.
If unsupported, consider gating those properties behind a provider capability check.
305-307: Endpoint correctness
Base URLhttps://api.z.aiand path/api/paas/v4/chat/completionsalign with current Z AI docs. Good catch separating it from the default/v1/...path.Also applies to: 352-354
packages/models/src/models/zai.ts (1)
22-22: Confirm thetest: "only"flag matches the typing ofProviderModelMapping
ProviderModelMappingwasn’t included in the context, so it’s unclear whether thetestfield exists or is currently typed as a literal"only". If the field is absent or its type does not allow the"only"value, TypeScript will error once the file is compiled.Please compile the workspace or run
tsc -p packages/modelsto ensure this flag passes type-checking.Also applies to: 45-45, 68-68, 91-91, 114-114, 137-137
Add new Z AI provider to the platform with corresponding models: GLM-4.5, GLM-4.5 Air, GLM-4.5 X, GLM-4.5 AirX, GLM-4.5 Flash, and GLM-4 32B (0414-128k). Integrate API key handling, provider logic, and API endpoint configurations to support Z AI models.
Summary by CodeRabbit
New Features
Chores
UI Improvements