LLM provider integrations for structured outputs in Python¶
Choose the service that hosts your model to find its SDK and credentials. For the string to pass to from_provider, see model IDs by provider.
-
Major Cloud Providers
Leading AI providers with comprehensive features
OpenAI Chat Completions · OpenAI-compatible gateways · OpenAI Responses · Azure OpenAI · Anthropic Claude · Google Gemini API · Vertex AI · AWS Bedrock · Google Gen AI SDK · xAI
-
Additional Cloud Providers
Other commercial AI providers with specialized offerings
Cohere · Mistral · DeepSeek · Together AI · Groq · Fireworks · Cerebras · Writer · Perplexity · SambaNova
-
Open Source
Run open-source models locally or in the cloud
-
Routing
Unified interfaces for multiple providers
Common Features¶
| Feature | Description | Documentation |
|---|---|---|
| Model Patching | Enhance provider clients with structured output capabilities | Patching |
| Response Models | Define expected response schema with Pydantic | Models |
| Validation | Ensure responses match your schema definition | Validation |
| Streaming | Stream partial or iterative responses | Partial, Iterable |
| Hooks | Add callbacks for monitoring and debugging | Hooks |
Provider Modes¶
Use the mode comparison to check whether your provider accepts tool calls, a JSON schema, or JSON instructions in the prompt.
Getting Started¶
1. Using Provider Initialization (Recommended)¶
Install instructor and set OPENAI_API_KEY to run this example.
import instructor
from pydantic import BaseModel
class UserInfo(BaseModel):
name: str
age: int
client = instructor.from_provider("openai/gpt-6-luna")
response = client.create(
response_model=UserInfo,
messages=[{"role": "user", "content": "Extract the name and age. Mina is 32."}],
reasoning_effort="none",
)
Provider Checklist¶
- Install the SDK and configure credentials as shown in your provider's guide.
- Choose a model ID and pass
"provider/model"tofrom_provider. - For asynchronous requests, set
async_client=Trueand awaitclient.create(...).
2. Manual Client Setup¶
If you already have an SDK client, use the matching Instructor factory. For example, wrap an OpenAI client with from_openai.
import instructor
from openai import OpenAI
client = instructor.from_openai(OpenAI(), model="gpt-6-luna")
Need Help?¶
Browse the examples, search GitHub issues, or join the Discord community.