# How to Run DeepSeek and Gemini Models inside the OpenAI Agents SDK

> **Author:** Owais Abdullah  
> **Published:** Oct 29, 2026  
> **Categories:** AI Agents  
> **Canonical URL:** https://owaisabdullah.dev/blog/how-to-run-deepseek-and-gemini-models-inside-the-openai-agents-sdk  

## Overview

Learn how to run DeepSeek and Gemini models inside OpenAI's Agents SDK using custom AsyncOpenAI clients, base URLs, and multi-model agent handoffs with runnable Python code examples.

## Content


> **TL;DR** - Running DeepSeek and Gemini models inside the OpenAI Agents SDK is straightforward when you configure custom AsyncOpenAI clients with vendor base URLs and pass them into OpenAIChatCompletionsModel, unlocking practical multi-model agent handoffs without rewriting your core architecture.


## How Do You Set Up Custom OpenAI Clients for Third-Party Providers?

When I build AI applications using the OpenAI Agents SDK, I often need to plug in non-OpenAI models without rewriting my entire agent architecture. The framework provides out-of-the-box support for any provider exposing an OpenAI-compatible endpoint. Instead of relying solely on default environment variables, you instantiate vendor-specific asynchronous clients by supplying a custom `base_url` and your respective API key.


![A professional developer](Image)

To configure custom base URLs in Python, you pass the provider endpoint directly into the client initializer. If your endpoint URL misses a trailing slash or version suffix, you will encounter connection errors. You can learn more about how I structure reliable automation pipelines in our guide to building robust AI workflows.

Here is how I set up asynchronous clients for DeepSeek and Gemini:


```python
import os
from openai import AsyncOpenAI

# Initialize DeepSeek client
deepseek_client = AsyncOpenAI(
    base_url="https://api.deepseek.com/v1",
    api_key=os.getenv("DEEPSEEK_API_KEY")
)

# Initialize Gemini client
gemini_client = AsyncOpenAI(
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
    api_key=os.getenv("GEMINI_API_KEY")
)
```

For comprehensive integration details, read the OpenAI Agents SDK Models Guide. You can also explore practical code examples in Build Agents with OpenAI SDK using any LLM Provider.


## How Do You Configure DeepSeek and Gemini with OpenAIChatCompletionsModel?

Once your provider clients are initialized, you assign them directly to agent instances using the `OpenAIChatCompletionsModel` class. In my multi-model pipelines, this lets each specialized agent use the exact model best suited for its specific task, such as routing heavy code generation to DeepSeek or summarization tasks to Gemini.

When choosing between providers, you balance inference speed and cost against reasoning capabilities. To pass model settings like temperature or max tokens, configure a `ModelSettings` object directly on your Agent instance.

Here is how I assign a DeepSeek model to a specialized bug-detection agent:


```python
from agents import Agent, OpenAIChatCompletionsModel
from agents.model_settings import ModelSettings

bugs_agent = Agent(
    name="DeepSeek Code Assistant",
    instructions="You review pull requests and detect code bugs.",
    model=OpenAIChatCompletionsModel(
        model="deepseek-chat",
        openai_client=deepseek_client,
    ),
    model_settings=ModelSettings(temperature=0.2)
)
```

To see how this pairs with persistent storage layers, check out our breakdown of Postgres and S3 memory layers for AI agents.

Here is how I configure a Gemini summarization agent as well:


```python
summary_agent = Agent(
    name="Gemini Summarizer",
    instructions="You summarize long technical documents.",
    model=OpenAIChatCompletionsModel(
        model="gemini-2.5-flash",
        openai_client=gemini_client,
    ),
    model_settings=ModelSettings(temperature=0.4)
)
```

Passing the custom client into the model parameter ensures your agent calls hit the third-party provider seamlessly. For multi-model routing tips, review LangDB's Agents SDK Integration Guide.


## How Do You Execute Multi-Model Agent Handoffs and Orchestration?

When I architect multi-provider workflows, I route initial triage through a lightweight OpenAI model while delegating heavy reasoning or cost-sensitive tasks to DeepSeek or Gemini agents.

Designing a reliable triage agent requires clear instructions and precise handoff descriptions so the router knows when to pass control. When a sub-agent completes its delegated task, control returns to the orchestrator or final output handler.


![A clean, professional diagram illustrating a multi-agent AI architecture with different specialized model nodes.](Image)

Here is how I structure a multi-model handoff workflow:


```python
from agents import Agent, Runner

triage_agent = Agent(
    name="Triage Agent",
    instructions="Route incoming queries to the correct specialist.",
    handoffs=[bugs_agent, summary_agent]
)

result = Runner.run_sync(triage_agent, "Check this python script for errors.")
print(result.final_output)
```

This modular architecture keeps your codebase clean and ensures every sub-task runs on the most efficient model. For peer troubleshooting and community feedback, check out the OpenAI Developer Community Discussion.


## How Do You Handle Tracing, Authentication, and Common Production Errors?

When running non-OpenAI models inside an OpenAI-centric SDK, developers often encounter authentication errors during telemetry export if an OpenAI API key is missing. Because traces attempt to upload to OpenAI servers by default, you must supply a valid trace key, disable telemetry using `set_tracing_disabled(True)`, or configure a custom processor.

To protect sensitive user data and prevent telemetry errors in local environments, I always disable tracing when testing third-party models:


```python
from agents import set_tracing_disabled

set_tracing_disabled(True)
```

Addressing these configuration nuances early ensures smooth local development and reliable production deployments. For visual debugging walkthroughs, watch the OpenAI Agents SDK Video Tutorial.


## Bottom Line

Running DeepSeek and Gemini models inside the OpenAI Agents SDK gives you complete model flexibility without sacrificing orchestration power. By utilizing custom `AsyncOpenAI` clients, `OpenAIChatCompletionsModel`, and multi-model agent handoffs, you can build cost-effective AI workflows tailored to your specific application needs as covered in our guide to building robust AI workflows.


## Sources

- Models - OpenAI Agents SDK (OpenAI)
- Build Agents with OpenAI SDK using any LLM Provider (Claude, Deepseek, Perplexity, Gemini…) | by Mohamed Amri | Medium (Medium)
- Use OpenAI Agents SDK with Gemini, Claude, DeepSeek ... - LangDB (LangDB)
- Using Gemini with OpenAI Agents SDK - API - OpenAI Developer Community (OpenAI Developer Community)
- Building AI Intelligent Apps using OpenAI, Gemini and DeepSeek API | BestITCourses (YouTube)

## Frequently Asked Questions

### Can I run DeepSeek and Gemini inside the OpenAI Agents SDK?

Yes. You can run third-party models by initializing an AsyncOpenAI client with a custom base_url and passing it into OpenAIChatCompletionsModel.

### How do I configure a custom base URL for Gemini or DeepSeek?

Instantiate AsyncOpenAI with the provider's specific API base URL and key, then pass that client object into the agent's model parameter.

### Why am I getting a 401 error when using non-OpenAI models?

A 401 error usually happens when the SDK attempts to upload traces to OpenAI servers without a valid OpenAI API key. Disable tracing using set_tracing_disabled(True) to fix it.

### Can I mix OpenAI models and third-party models in one workflow?

Yes. You can use agent handoffs to delegate tasks between an OpenAI triage agent and specialized sub-agents powered by DeepSeek or Gemini.

### Do third-party models support all OpenAI Agents SDK features?

Most chat completions features and handoffs work smoothly, but certain proprietary Responses API features or structured output schemas may require provider compatibility checks.

---
*Generated by Owais Abdullah Portfolio Agent Indexer (https://owaisabdullah.dev)*
