Study 70 files ยท 12 subfolders
Copy to Workspace 08_MODEL_PROVIDERS Shared from "Study" on Inkdown
Model Providers - Comprehensive Deep Dive
Overview
Model Providers are the abstraction layer that connects the OpenAI Agents SDK to various Large Language Model (LLM) APIs. Think of Model Providers as "translators" or "adapters" - they translate the SDK's standardized requests into the specific format required by different LLM providers (OpenAI, Anthropic, Google, etc.).
Core Concepts
What is a Model Provider?
A Model Provider is responsible for:
Resolving model names to concrete Model instances
Managing model connections and resources
Providing a consistent interface across different LLM APIs
Handling provider-specific features and quirks
Why Model Providers Matter
Provider Agnostic - Switch between LLM providers without changing agent code
Flexibility - Use the best model for each task
basic-ques
Cost Optimization - Use cheaper models for simple tasks
Redundancy - Fallback to alternative providers
Experimentation - Easy A/B testing of different models
Provider Architecture
Model Interface The base Model interface defines what all models must implement:
ModelProvider Interface The ModelProvider interface defines how models are resolved:
OpenAI Provider
OpenAIProvider The default provider for OpenAI models:
OpenAI Chat Completions Model Uses the OpenAI Chat Completions API:
You want to use the Chat Completions API
You need compatibility with older OpenAI integrations
You want more control over the API
OpenAI Responses Model Uses the newer OpenAI Responses API:
You want the latest OpenAI features
You need better tool support
You want server-managed conversations
You need prompt caching
OpenAI Responses WebSocket Model Uses WebSocket transport for Responses API:
You want real-time streaming
You need lower latency
You're building real-time applications
Default Model Selection The SDK has a default model:
GPT-5 Special Handling GPT-5 models require special reasoning settings:
The SDK automatically adjusts settings when you specify a GPT-5 model.
MultiProvider
Using Multiple Providers MultiProvider allows using multiple model providers:
Provider Priority Providers are tried in order:
Model Name Resolution Different providers use different model names:
Custom Model Providers
Creating a Custom Provider Implement the ModelProvider interface:
Creating a Custom Model Implement the Model interface:
Using Custom Provider
Model Settings
ModelSettings Class Configure model-specific parameters:
Temperature
Low (0.0-0.3): Factual responses, code generation
Medium (0.4-0.7): General conversation
High (0.8-1.5): Creative writing, brainstorming
Max Tokens
Penalties
Model Tracing
ModelTracing Enum Controls tracing behavior:
Tracing in Model Calls
Model Retry
Retry Advice Models can provide retry advice:
Retry Policies Configure retry behavior:
Provider-Specific Features
OpenAI Features Server-Managed Conversations:
Anthropic Features (via LiteLLM) Using Anthropic through LiteLLM:
Google Features (via LiteLLM) Using Google through LiteLLM:
Model Selection Strategies
Per-Agent Model Selection Different agents can use different models:
Run-Level Model Override Override model for a specific run:
Dynamic Model Selection Select model based on context:
Model Configuration
Global Default Configuration
Agent-Level Configuration Configure model on agent:
Run-Level Configuration Configure model for a run:
Configuration Priority Priority (highest to lowest):
RunConfig.model
Agent.model
Global default
Model Best Practices
1. Choose Appropriate Models Select the right model for the task:
2. Configure Temperature Appropriately Set temperature based on task:
3. Set Reasonable Token Limits
4. Handle Model Failures Implement fallback logic:
5. Monitor Model Usage Track model usage and costs:
Common Patterns
1. Tiered Model Usage Use different models for different complexity:
2. Model A/B Testing
3. Cost Optimization Use cheaper models when possible:
4. Model-Specific Prompts Adjust prompts per model:
5. Provider Redundancy Ensure availability with multiple providers:
Model and Tracing
Model-Level Tracing
Sensitive Data Handling
Summary Model Providers enable flexible LLM integration. Key takeaways:
Model Providers abstract LLM API differences
Model interface defines the contract for all models
ModelProvider interface defines model resolution
OpenAIProvider is the default provider
OpenAIChatCompletionsModel uses the Chat Completions API
OpenAIResponsesModel uses the newer Responses API
OpenAIResponsesWSModel uses WebSocket transport
MultiProvider enables using multiple providers
Custom providers can integrate any LLM API
ModelSettings configures model parameters
Temperature controls randomness
Max tokens limits response length
Penalties control repetition
ModelTracing controls observability
Retry advice provides error recovery hints
Provider-specific features like server-managed conversations
LiteLLM enables using 100+ LLM providers
Per-agent model selection for different tasks
Run-level overrides for specific runs
Configuration priority determines which settings apply
Model Providers are essential for building flexible, cost-effective, and resilient agent systems.