Skip to content

feat(providers): add xAI to hosted key rotation pool#5574

Open
waleedlatif1 wants to merge 3 commits into
stagingfrom
worktree-feat+xai-hosted-keys
Open

feat(providers): add xAI to hosted key rotation pool#5574
waleedlatif1 wants to merge 3 commits into
stagingfrom
worktree-feat+xai-hosted-keys

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Add xAI (Grok) to the hosted-key mechanism, mirroring OpenAI/Anthropic/Z.ai exactly
  • XAI_API_KEY_1/2/3 env vars + getRotatingApiKey('xai') rotation pool
  • xai added to getHostedModels() so Grok models are billed/served with Sim's key when no BYOK key is set
  • xai added to BYOKProviderId union + byokProviderIdSchema (workspace BYOK still works, no UI settings row added — same as zai, which is hosted-only today)

Type of Change

  • New feature

Testing

  • bun run check:api-validation passes
  • bunx tsc --noEmit clean on touched files (2 pre-existing unrelated errors elsewhere on staging)
  • bunx vitest run lib/core/utils.test.ts providers/models.test.ts lib/api-key/byok.test.ts providers/utils.test.ts — 222/222 passing
  • bun run lint clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Wires xai into the same hosted-key mechanism as OpenAI, Anthropic,
and Z.ai so Sim can serve Grok models without users bringing their
own key.
@vercel

vercel Bot commented Jul 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 10, 2026 10:16pm

Request Review

@cursor

cursor Bot commented Jul 10, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes API key selection and hosted-model billing for a new provider; behavior mirrors existing hosted providers but misconfigured env keys could break Grok inference or billing expectations.

Overview
Adds xAI (Grok) to the same hosted-key and BYOK paths used for OpenAI, Anthropic, Google, and Z.ai.

Hosted: XAI_API_KEY_1/2/3 env vars and getRotatingApiKey('xai'); xAI models are included in getHostedModels() so grok-4.5 is served and billed with Sim’s rotating key when no workspace BYOK key is set. getApiKeyWithBYOK and provider utils treat xai like other hosted providers.

BYOK: xai is added to BYOKProviderId, the BYOK API schema, Pi cloud workspace key fallback (WORKSPACE_BYOK_PROVIDERS), and the workspace Settings → BYOK Models section (with xAIIcon).

Tests cover rotation, hosted-model lists, billing eligibility, Pi cloud BYOK fallback, and the xAI provider definition.

Reviewed by Cursor Bugbot for commit dfc0868. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds xAI/Grok support to the hosted key and BYOK paths. The main changes are:

  • xAI provider IDs are accepted by the BYOK contract and shared provider type.
  • xAI appears in the workspace BYOK settings UI.
  • Hosted Grok models can use the xAI rotating key pool.
  • Pi cloud key resolution now checks stored workspace xAI keys.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
apps/sim/executor/handlers/pi/keys.ts Adds xAI to the Pi cloud workspace BYOK lookup set.
apps/sim/app/workspace/[workspaceId]/settings/components/byok/byok.tsx Adds xAI to the BYOK settings provider list and Models section.
apps/sim/lib/api/contracts/byok-keys.ts Adds xAI as an accepted BYOK provider ID.
apps/sim/lib/api-key/byok.ts Adds xAI to hosted workspace key resolution.
apps/sim/providers/utils.ts Adds xAI to hosted API key selection.
apps/sim/lib/core/config/api-keys.ts Adds xAI hosted key rotation using XAI API key environment variables.
apps/sim/providers/models.ts Adds xAI models to the hosted model list.

Reviews (3): Last reviewed commit: "fix(byok): add xai settings UI row" | Re-trigger Greptile

Comment thread apps/sim/lib/api/contracts/byok-keys.ts
Comment thread apps/sim/tools/types.ts
xai was fully wired as a Pi-supported provider but missing from
WORKSPACE_BYOK_PROVIDERS, so a stored workspace xAI key was never
read back for cloud-mode Pi runs.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/providers/models.ts
xai is both hosted (Pi block hides its inline API key field for
hosted models) and Pi-supported (cloud mode requires a user key),
so without a Settings > BYOK row users had no way to supply an xai
key for Pi cloud runs.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit dfc0868. Configure here.

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.

1 participant