You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
about: Questions or bugs about using non-OpenAI models
4
+
title: ''
5
+
labels: bug
6
+
assignees: ''
7
+
8
+
---
9
+
10
+
### Please read this first
11
+
12
+
-**Have you read the custom model provider docs, including the 'Common issues' section?**[Model provider docs](https://openai.github.io/openai-agents-python/models/#using-other-llm-providers)
13
+
-**Have you searched for related issues?** Others may have faced similar issues.
14
+
15
+
### Describe the question
16
+
A clear and concise description of what the question or bug is.
17
+
18
+
### Debug information
19
+
- Agents SDK version: (e.g. `v0.0.3`)
20
+
- Python version (e.g. Python 3.10)
21
+
22
+
### Repro steps
23
+
Ideally provide a minimal python script that can be run to reproduce the issue.
24
+
25
+
### Expected behavior
26
+
A clear and concise description of what you expected to happen.
Copy file name to clipboardExpand all lines: README.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,11 @@ print(result.final_output)
47
47
48
48
(_If running this, ensure you set the `OPENAI_API_KEY` environment variable_)
49
49
50
+
(_For Jupyter notebook users, see [hello_world_jupyter.py](examples/basic/hello_world_jupyter.py)_)
51
+
50
52
## Handoffs example
51
53
52
-
```py
54
+
```python
53
55
from agents import Agent, Runner
54
56
import asyncio
55
57
@@ -140,7 +142,7 @@ The Agents SDK is designed to be highly flexible, allowing you to model a wide r
140
142
141
143
## Tracing
142
144
143
-
The Agents SDK automatically traces your agent runs, making it easy to track and debug the behavior of your agents. Tracing is extensible by design, supporting custom spans and a wide variety of external destinations, including [Logfire](https://logfire.pydantic.dev/docs/integrations/llms/openai/#openai-agents), [AgentOps](https://docs.agentops.ai/v1/integrations/agentssdk), and [Braintrust](https://braintrust.dev/docs/guides/traces/integrations#openai-agents-sdk). For more details about how to customize or disable tracing, see [Tracing](http://openai.github.io/openai-agents-python/tracing).
145
+
The Agents SDK automatically traces your agent runs, making it easy to track and debug the behavior of your agents. Tracing is extensible by design, supporting custom spans and a wide variety of external destinations, including [Logfire](https://logfire.pydantic.dev/docs/integrations/llms/openai/#openai-agents), [AgentOps](https://docs.agentops.ai/v1/integrations/agentssdk), [Braintrust](https://braintrust.dev/docs/guides/traces/integrations#openai-agents-sdk), [Scorecard](https://docs.scorecard.io/docs/documentation/features/tracing#openai-agents-sdk-integration), and [Keywords AI](https://docs.keywordsai.co/integration/development-frameworks/openai-agent). For more details about how to customize or disable tracing, see [Tracing](http://openai.github.io/openai-agents-python/tracing).
144
146
145
147
## Development (only needed if you need to edit the SDK/examples)
Copy file name to clipboardExpand all lines: docs/models.md
+35-15Lines changed: 35 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -53,21 +53,41 @@ async def main():
53
53
54
54
## Using other LLM providers
55
55
56
-
Many providers also support the OpenAI API format, which means you can pass a `base_url` to the existing OpenAI model implementations and use them easily. `ModelSettings` is used to configure tuning parameters (e.g., temperature, top_p) for the model you select.
56
+
You can use other LLM providers in 3 ways (examples [here](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/)):
57
57
58
-
```python
59
-
external_client = AsyncOpenAI(
60
-
api_key="EXTERNAL_API_KEY",
61
-
base_url="https://api.external.com/v1/",
62
-
)
58
+
1.[`set_default_openai_client`][agents.set_default_openai_client] is useful in cases where you want to globally use an instance of `AsyncOpenAI` as the LLM client. This is for cases where the LLM provider has an OpenAI compatible API endpoint, and you can set the `base_url` and `api_key`. See a configurable example in [examples/model_providers/custom_example_global.py](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/custom_example_global.py).
59
+
2.[`ModelProvider`][agents.models.interface.ModelProvider] is at the `Runner.run` level. This lets you say "use a custom model provider for all agents in this run". See a configurable example in [examples/model_providers/custom_example_provider.py](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/custom_example_provider.py).
60
+
3.[`Agent.model`][agents.agent.Agent.model] lets you specify the model on a specific Agent instance. This enables you to mix and match different providers for different agents. See a configurable example in [examples/model_providers/custom_example_agent.py](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/custom_example_agent.py).
61
+
62
+
In cases where you do not have an API key from `platform.openai.com`, we recommend disabling tracing via `set_tracing_disabled()`, or setting up a [different tracing processor](tracing.md).
63
+
64
+
!!! note
65
+
66
+
In these examples, we use the Chat Completions API/model, because most LLM providers don't yet support the Responses API. If your LLM provider does support it, we recommend using Responses.
67
+
68
+
## Common issues with using other LLM providers
69
+
70
+
### Tracing client error 401
71
+
72
+
If you get errors related to tracing, this is because traces are uploaded to OpenAI servers, and you don't have an OpenAI API key. You have three options to resolve this:
2. Set an OpenAI key for tracing: [`set_tracing_export_api_key(...)`][agents.set_tracing_export_api_key]. This API key will only be used for uploading traces, and must be from [platform.openai.com](https://platform.openai.com/).
76
+
3. Use a non-OpenAI trace processor. See the [tracing docs](tracing.md#custom-tracing-processors).
77
+
78
+
### Responses API support
79
+
80
+
The SDK uses the Responses API by default, but most other LLM providers don't yet support it. You may see 404s or similar issues as a result. To resolve, you have two options:
81
+
82
+
1. Call [`set_default_openai_api("chat_completions")`][agents.set_default_openai_api]. This works if you are setting `OPENAI_API_KEY` and `OPENAI_BASE_URL` via environment vars.
83
+
2. Use [`OpenAIChatCompletionsModel`][agents.models.openai_chatcompletions.OpenAIChatCompletionsModel]. There are examples [here](https://github.com/openai/openai-agents-python/tree/main/examples/model_providers/).
84
+
85
+
### Structured outputs support
86
+
87
+
Some model providers don't have support for [structured outputs](https://platform.openai.com/docs/guides/structured-outputs). This sometimes results in an error that looks something like this:
63
88
64
-
spanish_agent = Agent(
65
-
name="Spanish agent",
66
-
instructions="You only speak Spanish.",
67
-
model=OpenAIChatCompletionsModel(
68
-
model="EXTERNAL_MODEL_NAME",
69
-
openai_client=external_client,
70
-
),
71
-
model_settings=ModelSettings(temperature=0.5),
72
-
)
73
89
```
90
+
BadRequestError: Error code: 400 - {'error': {'message': "'response_format.type' : value is not one of the allowed values ['text','json_object']", 'type': 'invalid_request_error'}}
91
+
```
92
+
93
+
This is a shortcoming of some model providers - they support JSON outputs, but don't allow you to specify the `json_schema` to use for the output. We are working on a fix for this, but we suggest relying on providers that do have support for JSON schema output, because otherwise your app will often break because of malformed JSON.
0 commit comments