Skip to content

fix(py): forward api_key kwargs to litellm validation#202

Open
vincent067 wants to merge 1 commit into
getomni-ai:mainfrom
vincent067:fix/forward-api-key-to-litellm
Open

fix(py): forward api_key kwargs to litellm validation#202
vincent067 wants to merge 1 commit into
getomni-ai:mainfrom
vincent067:fix/forward-api-key-to-litellm

Conversation

@vincent067
Copy link
Copy Markdown

Hi there! 👋

This PR fixes #190api_key passed via kwargs was being dropped during validation in the Python SDK.

What was broken

Currently, if you pass api_key directly to zerox():

result = await zerox(
    file_path="doc.pdf",
    model="gpt-4o-mini",
    api_key="sk-xxx"  # passed via kwargs
)

…it still fails with:

MissingEnvironmentVariables: missing_keys: ['OPENAI_API_KEY']

That happens because litellm.validate_environment() and litellm.check_valid_key() both support an api_key parameter, but litellmmodel was never forwarding it.

The fix

Two small changes in py_zerox/pyzerox/models/modellitellm.py:

  1. validate_environment — now passes api_key=self.kwargs.get(\"api_key\") to litellm.validate_environment()
  2. validate_access — now passes api_key=self.kwargs.get(\"api_key\") to litellm.check_valid_key() instead of hard-coding None

This makes per-request API key injection work as expected, which is important for multi-tenant apps and testing environments where global env vars aren't desirable.

Let me know if you'd like any tweaks — happy to iterate! 😊

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.

Support passing api_key via kwargs instead of only environment variables

1 participant