Skip to content

[EPD-194] Make missing OPENAI_API_KEY error actionable (env var / api_key / AMP scope)#6538

Open
joaomdmoura wants to merge 1 commit into
mainfrom
joao/epd-194-amp-code-first-deployments-cant-use-org-wide-llm-connections
Open

[EPD-194] Make missing OPENAI_API_KEY error actionable (env var / api_key / AMP scope)#6538
joaomdmoura wants to merge 1 commit into
mainfrom
joao/epd-194-amp-code-first-deployments-cant-use-org-wide-llm-connections

Conversation

@joaomdmoura

@joaomdmoura joaomdmoura commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator
  • Rewrites the bare ValueError("OPENAI_API_KEY is required") in the OpenAI provider (lib/crewai/src/crewai/llms/providers/openai/completion.py) to explain the remediation: set the OPENAI_API_KEY environment variable or pass api_key to LLM(), and that org-wide LLM Connections do not apply to code-first CrewAI AMP deployments (which read keys from deployment environment variables).
  • Adds test_openai_missing_api_key_error_is_actionable asserting the new message content.
  • Updates the CLI deploy-validate test's simulated provider error to the new shipped string; the llm_init_missing_key classifier regex still matches.
  • Linear: https://linear.app/crewai/issue/EPD-194

🤖 Generated with Claude Code


Note

Low Risk
User-facing error text and test fixtures only; no auth or runtime behavior changes beyond clearer failures when the key is missing.

Overview
Replaces the bare OPENAI_API_KEY is required ValueError in OpenAICompletion._get_client_params with guidance to set OPENAI_API_KEY, pass api_key to LLM(), and a note that org-wide LLM Connections do not apply to code-first CrewAI AMP deployments (keys come from deployment environment variables).

Adds test_openai_missing_api_key_error_is_actionable to lock in that message. Updates the deploy validator test’s simulated import error to the new provider string; llm_init_missing_key classification is unchanged.

Reviewed by Cursor Bugbot for commit 47bbb8a. Bugbot is set up for automated code reviews on this repo. Configure here.

The OpenAI provider raised a bare "OPENAI_API_KEY is required", which
misdirects CrewAI AMP users who configured an org-wide LLM Connection.
The error now explains the remediation (set the OPENAI_API_KEY
environment variable or pass api_key to LLM()) and clarifies that
org-wide LLM Connections do not apply to code-first AMP deployments,
which read keys from deployment environment variables.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@linear

linear Bot commented Jul 14, 2026

Copy link
Copy Markdown

EPD-194

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: de6c3c47-7bd6-4c11-916f-de050296049d

📥 Commits

Reviewing files that changed from the base of the PR and between 9d72e26 and 47bbb8a.

📒 Files selected for processing (3)
  • lib/cli/tests/deploy/test_validate.py
  • lib/crewai/src/crewai/llms/providers/openai/completion.py
  • lib/crewai/tests/llms/openai/test_openai.py

📝 Walkthrough

Walkthrough

The OpenAI provider now reports actionable guidance when OPENAI_API_KEY is missing. Provider and CLI tests were updated to validate the expanded multi-line message and its warning classification.

Changes

OpenAI API key error handling

Layer / File(s) Summary
Actionable missing-key guidance
lib/crewai/src/crewai/llms/providers/openai/completion.py, lib/crewai/tests/llms/openai/test_openai.py, lib/cli/tests/deploy/test_validate.py
The provider emits setup instructions for environment variables and LLM(api_key=...), while tests verify the message content and CLI warning classification.

Suggested reviewers: greysonlalonde, lorenzejay

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: making the missing OPENAI_API_KEY error actionable.
Description check ✅ Passed The description matches the code changes and test updates in the PR.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch joao/epd-194-amp-code-first-deployments-cant-use-org-wide-llm-connections

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant