Skip to content

🐛 fix(docs): stop the Groq client from failing next build - #96

Merged
vtempest merged 1 commit into
masterfrom
claude/youthful-cori-6vdody
Sep 11, 2026
Merged

🐛 fix(docs): stop the Groq client from failing next build#96
vtempest merged 1 commit into
masterfrom
claude/youthful-cori-6vdody

Conversation

@vtempest

Copy link
Copy Markdown
Collaborator

The failure

The Vercel build died during page-data collection:

Error: Groq API key not found. Please set the GROQ_API_KEY environment variable or provide the key into "apiKey"
> Build error occurred
Error: Failed to collect page data for /api/chat

next build evaluates every route module while collecting page data. apps/docs/src/lib/ai/providers.ts built its clients at module scope:

export const chatModel = new ChatGroq({ model: 'llama-3.3-70b-versatile', temperature: 0 })

new ChatGroq() throws when GROQ_API_KEY is absent, so importing /api/chat — which the build does — failed on any machine without the key. Turbo also warned it was dropping GROQ_API_KEY, so even a configured Vercel project would not have passed it through.

The fix

  • Lazy providers. getChatModel() / getEmbeddingModel() construct on first use and cache. Nothing runs at import time, so the build no longer needs a key. A missing key raises a MissingApiKeyError at request time.
  • /api/chat degrades instead of crashing — 503 with the "set GROQ_API_KEY" message when the key is absent.
  • turbo.json declares GROQ_API_KEY and OPENAI_API_KEY in the build task's env, clearing the platform-environment-variable warning so the keys reach the build when they are set.
  • @radix-ui/react-tabs is declared in apps/docs/package.json. src/components/ui/tabs.tsx imports it directly but it was only ever resolved transitively; a cold install here failed to compile with Module not found: Can't resolve '@radix-ui/react-tabs'.

Verification

  • With GROQ_API_KEY and OPENAI_API_KEY unset, importing providers.ts now succeeds; getChatModel() throws only when called (MissingApiKeyError: GROQ_API_KEY is not set…). Before this change the import itself threw — exactly the build failure.
  • bun run build in apps/docs gets past Collecting page data without touching /api/chat. (The build cannot finish in this sandbox: MDX image sizing needs i.imgur.com, which egress policy blocks, and @takumi-rs/image-response has no native binding here. Both are environment limits, not code.)
  • bun run readmes:check passes.
  • bun run typecheck reports the same 160 pre-existing errors before and after — no regression, and CI/Vercel skip type validation.

Heads-up, not fixed here

A cold bun install today resolves fumadocs-openapi@10.10.3 against fumadocs-ui@16.15.9, and that pair does not compile: fumadocs-openapi/dist/ui/client/i18n.js imports useTranslations from fumadocs-ui/contexts/i18n, which 16.15.9 renamed to useI18n. Neither is pinned (^10.1.3, ^16.2.5) and no root lockfile is committed, so this is luck of the resolve — the deployment in the log compiled fine. Upgrading to fumadocs-openapi@11 is a real migration (fumadocs-openapi/ui/client moves), so it is out of scope for this fix. Pinning fumadocs-ui to the last version that exports useTranslations would be the quick lid if it bites.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Qk1775Kp6y6mLQXosPUght


Generated by Claude Code

`next build` evaluates every route module while collecting page data, so the
module-scope `new ChatGroq()` in `src/lib/ai/providers.ts` threw "Groq API key
not found" on any build machine without `GROQ_API_KEY`, failing the Vercel
build at "Collecting page data for /api/chat".

- Construct the chat and embedding models lazily, on first use, and cache them.
  A missing key now surfaces as a `MissingApiKeyError` at request time instead
  of at import time.
- `/api/chat` answers 503 with that message rather than crashing when the key
  is absent.
- Declare `GROQ_API_KEY` and `OPENAI_API_KEY` in the `build` task's `env` so
  turbo passes the platform environment variables through (turbo warned that it
  was dropping them).
- Declare `@radix-ui/react-tabs`, which `components/ui/tabs.tsx` imports
  directly but which was only ever resolved transitively; a cold install fails
  to compile without it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qk1775Kp6y6mLQXosPUght
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
app-demo Building Building Preview Sep 11, 2026 3:12pm UTC
cccp-deployment Building Building Preview Sep 11, 2026 3:12pm UTC

@vtempest
vtempest merged commit 989b7e2 into master Sep 11, 2026
19 of 22 checks passed
@vtempest
vtempest deleted the claude/youthful-cori-6vdody branch September 11, 2026 15:12
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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