Skip to content

fix(slack): use validated env for Anthropic API key#1067

Merged
saddlepaddle merged 1 commit intomainfrom
satya-patel/anthropic-api-key
Jan 30, 2026
Merged

fix(slack): use validated env for Anthropic API key#1067
saddlepaddle merged 1 commit intomainfrom
satya-patel/anthropic-api-key

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Jan 30, 2026

Summary

  • Anthropic SDK was using implicit process.env.ANTHROPIC_API_KEY which wasn't set in Vercel deployments, causing Could not resolve authentication method errors
  • Now uses validated env.ANTHROPIC_API_KEY from the API's env.ts (Zod-validated at build time)
  • Added ANTHROPIC_API_KEY to deploy-preview and deploy-production workflows
  • Removed unused ANTHROPIC_API_KEY from trpc env.ts

Test plan

  • Deploy to preview and trigger a Slack mention — verify agent no longer errors with auth resolution failure

Summary by CodeRabbit

  • Chores
    • Updated deployment configuration to properly handle API credentials across environments.
    • Refined environment variable configuration and validation for the API service.

✏️ Tip: You can customize this high-level summary in your review settings.

The Anthropic SDK defaulted to process.env.ANTHROPIC_API_KEY which was
not set in the Vercel deployment. Pass the key explicitly via the
validated env.ts config.

- Add ANTHROPIC_API_KEY to API env.ts as required
- Pass env.ANTHROPIC_API_KEY to Anthropic client in run-agent.ts
- Add to deploy-preview and deploy-production workflows
- Remove unused ANTHROPIC_API_KEY from trpc env.ts
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

This pull request adds ANTHROPIC_API_KEY environment variable configuration across the codebase. The key is added to GitHub Actions deployment workflows, integrated into environment schemas, and used for Anthropic client initialization in the Slack agent service.

Changes

Cohort / File(s) Summary
GitHub Actions Workflows
.github/workflows/deploy-preview.yml, .github/workflows/deploy-production.yml
Added ANTHROPIC_API_KEY to environment configuration in both preview and production deployment jobs, ensuring the API key is passed to Vercel during deployment.
Environment Schema Configuration
apps/api/src/env.ts, packages/trpc/src/env.ts
Added ANTHROPIC_API_KEY as a string variable to the server environment schema in the API package; removed it from the tRPC package schema. Also relaxed SLACK_SIGNING_SECRET validation from required to optional.
Agent Implementation
apps/api/src/app/api/integrations/slack/events/utils/run-agent/run-agent.ts
Updated Anthropic client initialization to explicitly use the ANTHROPIC_API_KEY from environment configuration instead of relying on default credentials.

Possibly Related PRs

Poem

🐰 Hops through the workflows with key in paw,
Environment variables, none without flaw,
From preview to production, the secrets now flow,
Anthropic awaits—let the agents go!

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: using validated env for the Anthropic API key instead of implicit process.env.
Description check ✅ Passed The description covers the issue, solution, changes made, and includes a test plan, but is missing a formal Description section and Related Issues link per the template.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch satya-patel/anthropic-api-key

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 and usage tips.

@saddlepaddle saddlepaddle merged commit e5af9ac into main Jan 30, 2026
12 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 30, 2026

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) View Branch
Fly.io Electric (Fly.io) View App
Vercel API (Vercel) Open Preview
Vercel Web (Vercel) Open Preview
Vercel Marketing (Vercel) Open Preview
Vercel Admin (Vercel) Open Preview
Vercel Docs (Vercel) Open Preview

Preview updates automatically with new commits

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