Set up your LLM provider¶
Once you've installed Instructor, choose a provider and set its credentials in the environment where you run Python.
Choose an SDK and API key¶
The base install includes the OpenAI SDK. For other providers, install the extra listed below. If you use a uv project, replace python -m pip install with uv add.
| Provider | Install command | Environment variable |
|---|---|---|
| OpenAI | python -m pip install instructor | OPENAI_API_KEY |
| Anthropic Claude | python -m pip install "instructor[anthropic]" | ANTHROPIC_API_KEY |
| Google Gemini | python -m pip install "instructor[google-genai]" | GOOGLE_API_KEY |
| Cohere | python -m pip install "instructor[cohere]" | CO_API_KEY |
| Mistral | python -m pip install "instructor[mistral]" | MISTRAL_API_KEY |
For LiteLLM, install instructor[litellm] and configure credentials for the underlying provider. See all integrations for local models and cloud platforms.
Set your API key¶
For the OpenAI example below, replace the placeholder with your key. Run Python from the same shell.
Test a request¶
To test your API key, ask OpenAI to extract a name and age. To check installation locally, print the installed version.
import instructor
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
client = instructor.from_provider("openai/gpt-6-luna")
person = client.create(
response_model=Person,
messages=[{"role": "user", "content": "John Doe is 30 years old."}],
)
print(person.name, person.age)
To use Claude, install the Anthropic extra, set ANTHROPIC_API_KEY, and change the provider string to anthropic/claude-haiku-5-5.
Next, extract your first record or learn how to define a response model.