openai-agents-python/examples/model_providers
Rohan Mehta a0254b0b74
RFC: automatically use litellm if possible (#534)
## Summary
This replaces the default model provider with a `MultiProvider`, which
has the logic:
- if the model name starts with `openai/` or doesn't contain "/", use
OpenAI
- if the model name starts with `litellm/`, use LiteLLM to use the
appropriate model provider.

It's also extensible, so users can create their own mappings. I also
imagine that if we natively supported Anthropic/Gemini etc, we can add
it to MultiProvider to make it work.

The goal is that it should be really easy to use any model provider.
Today if you pass `model="gpt-4.1"`, it works great. But
`model="claude-sonnet-3.7"` doesn't. If we can make it that easy, it's a
win for devx.

I'm not entirely sure if this is a good idea - is it too magical? Is the
API too reliant on litellm? Comments welcome.

## Test plan

For now, the example. Will add unit tests if we agree its worth mergin.

---------

Co-authored-by: Steven Heidel <steven@heidel.ca>
2025-04-21 15:03:06 -04:00
..
custom_example_agent.py Update custom models to use tools 2025-03-13 13:10:26 -04:00
custom_example_global.py Update custom models to use tools 2025-03-13 13:10:26 -04:00
custom_example_provider.py Update custom models to use tools 2025-03-13 13:10:26 -04:00
litellm_auto.py RFC: automatically use litellm if possible (#534) 2025-04-21 15:03:06 -04:00
litellm_provider.py Litellm integration (#524) 2025-04-16 18:48:41 -04:00
README.md Add examples and documentation for using custom model providers 2025-03-12 17:34:38 -07:00

Custom LLM providers

The examples in this directory demonstrate how you might use a non-OpenAI LLM provider. To run them, first set a base URL, API key and model.

export EXAMPLE_BASE_URL="..."
export EXAMPLE_API_KEY="..."
export EXAMPLE_MODEL_NAME"..."

Then run the examples, e.g.:

python examples/model_providers/custom_example_provider.py

Loops within themselves,
Function calls its own being,
Depth without ending.