Skip to content

feat(models): add Z AI models and provider integration - #566

Merged
steebchen merged 3 commits into
mainfrom
feat/zai
Aug 3, 2025
Merged

steebchen merged 3 commits into
mainfrom
feat/zai

Conversation

@steebchen

@steebchen steebchen commented Aug 3, 2025

Copy link
Copy Markdown
Member

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

    • Added support for the "Z AI" provider, including integration of multiple "GLM-4.5" model variants.
    • "Z AI" models now available with features such as streaming, tools, and JSON output.
    • "Z AI" provider information and icon are now visible alongside other supported providers.
  • Chores

    • Updated workflow and environment configuration to support the new "Z AI" provider.
  • UI Improvements

    • Adjusted logo spacing for better visual alignment in the provider section.

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.
@coderabbitai

coderabbitai Bot commented Aug 3, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Support 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

Cohort / File(s) Change Summary
GitHub Actions Workflow Update
.github/workflows/run.yml
Adds Z_AI_API_KEY as a secret environment variable for jobs in the workflow.
Provider Environment Variable Mapping
apps/gateway/src/lib/provider.ts
Maps the "zai" provider to the Z_AI_API_KEY environment variable in providerEnvVarMap.
Provider Metadata Registration
packages/models/src/providers.ts
Adds a new "Z AI" provider entry to the exported providers array, including metadata and capabilities.
Model Definitions
packages/models/src/models/zai.ts, packages/models/src/models.ts
Introduces zaiModels with multiple "GLM-4.5" family models and includes them in the exported models array.
Provider API Integration
packages/models/src/provider-api.ts
Updates switch cases to handle "zai" for headers, request body, and endpoint construction, integrating the provider into API request flows.
UI Provider Icon and Logo
apps/ui/src/components/ui/providers-icons.tsx, apps/ui/src/components/provider-keys/provider-logo.ts
Adds ZaiIcon React component and maps the "zai" provider ID to this icon in providerLogoUrls.
UI Layout Adjustment
apps/ui/src/components/providers/hero.tsx
Adds vertical margin spacing to the logo container for better visual alignment.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • steebchen

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8cb85fb and 9cd9bc8.

📒 Files selected for processing (3)
  • apps/ui/src/components/provider-keys/provider-logo.ts (1 hunks)
  • apps/ui/src/components/providers/hero.tsx (1 hunks)
  • apps/ui/src/components/ui/providers-icons.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • apps/ui/src/components/provider-keys/provider-logo.ts
  • apps/ui/src/components/providers/hero.tsx
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

Use localStorage instead of cookies for client-side data persistence

Files:

  • apps/ui/src/components/ui/providers-icons.tsx
apps/ui/**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)

In apps/ui (a tanstack router project), always use navigate() for navigation

Use localStorage instead of cookies for client-side data persistence

Files:

  • apps/ui/src/components/ui/providers-icons.tsx
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • apps/ui/src/components/ui/providers-icons.tsx
🧬 Code Graph Analysis (1)
apps/ui/src/components/ui/providers-icons.tsx (1)
apps/ui/src/lib/utils.ts (1)
  • cn (4-6)
⏰ 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)
  • GitHub Check: build / run
  • GitHub Check: e2e / run
🔇 Additional comments (2)
apps/ui/src/components/ui/providers-icons.tsx (2)

511-525: LGTM! Well-implemented provider icon following established patterns.

The ZaiIcon component correctly follows the same structure and conventions as other provider icons in the file. The implementation properly uses TypeScript types, spreads props, handles className merging with the cn utility, and uses currentColor for theme compatibility.


545-545: LGTM! Correct addition to provider icons export map.

The zai: ZaiIcon mapping follows the established pattern and enables the icon to be accessed consistently with other provider icons throughout the application.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/zai

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@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: 0

🧹 Nitpick comments (3)
packages/models/src/models/zai.ts (3)

3-142: Avoid hand-written repetition – generate the six variants programmatically

Virtually every property other than id, name, and (implicitly) modelName is 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 readability

The 0.11 / 1e6 and 0.28 / 1e6 literals 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 explicit undefined fields to reduce noise

Properties set to undefined can simply be left out—their absence conveys the same meaning while shortening each object.

Example:

-	deprecatedAt: undefined,
-	deactivatedAt: undefined,
+	// no deprecation / deactivation

Same 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c7bf2e and cd14370.

📒 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.ts
  • packages/models/src/models.ts
  • packages/models/src/provider-api.ts
  • packages/models/src/providers.ts
  • packages/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 use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/provider.ts
  • packages/models/src/models.ts
  • packages/models/src/provider-api.ts
  • packages/models/src/providers.ts
  • packages/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, use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/gateway/src/lib/provider.ts
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • apps/gateway/src/lib/provider.ts
  • packages/models/src/models.ts
  • packages/models/src/provider-api.ts
  • packages/models/src/providers.ts
  • packages/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: zaiZ_AI_API_KEY mapping 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_KEY is 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
Importing zaiModels and 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, and reasoning_effort are 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 URL https://api.z.ai and path /api/paas/v4/chat/completions align 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 the test: "only" flag matches the typing of ProviderModelMapping

ProviderModelMapping wasn’t included in the context, so it’s unclear whether the test field 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/models to ensure this flag passes type-checking.

Also applies to: 45-45, 68-68, 91-91, 114-114, 137-137

@steebchen
steebchen enabled auto-merge August 3, 2025 22:28
@steebchen
steebchen added this pull request to the merge queue Aug 3, 2025
Merged via the queue into main with commit c00be73 Aug 3, 2025
10 checks passed
@steebchen
steebchen deleted the feat/zai branch August 3, 2025 22:30
@coderabbitai coderabbitai Bot mentioned this pull request Dec 22, 2025
4 tasks
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