Skip to content

Accept api_key in from_provider #1542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeroenvds opened this issue May 22, 2025 · 2 comments · May be fixed by #1554
Open

Accept api_key in from_provider #1542

jeroenvds opened this issue May 22, 2025 · 2 comments · May be fixed by #1554
Assignees
Labels
enhancement New feature or request python Pull requests that update python code

Comments

@jeroenvds
Copy link

Is your feature request related to a problem? Please describe.
It would be helpful if you could provide the API key as part of the from_provider constructor, as settings are often managed outside the environment variables. Currently the only option is to pass it to the client, but that removes the LLM provider-agnostic solution of from_provider()

Describe the solution you'd like
This code should be accepted

    instructor_client = instructor.from_provider(
        model=settings.LLM_MODEL,
        api_key=settings.LLM_API_KEY
    )

Today this results in an Exception:
The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

Describe alternatives you've considered

  • Environment variables: Not easy to change at runtime etc.
  • Setting the API key directly on the client: Impossible to write LLM provider-agnostic code

Additional context
n/a

@github-actions github-actions bot added enhancement New feature or request python Pull requests that update python code labels May 22, 2025
@Gable-github
Copy link

@jxnl i would like to work on this enhancement. Could you assign this issue to me? Thanks!

@jxnl
Copy link
Collaborator

jxnl commented May 22, 2025

@jxnl i would like to work on this enhancement. Could you assign this issue to me? Thanks!

ty!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Pull requests that update python code
Projects
None yet
3 participants