# Running DeepSeek and Gemini in the OpenAI Agents SDK: Cut API Costs by 90%

> **Author:** Owais Abdullah  
> **Published:** Oct 28, 2026  
> **Categories:** AI Agents  
> **Canonical URL:** https://owaisabdullah.dev/blog/running-deepseek-and-gemini-in-the-openai-agents-sdk-cut-api-costs-by-90  

## Overview

Learn how to run DeepSeek and Gemini models in the OpenAI Agents SDK using custom AsyncOpenAI clients, base URLs, and multi-model handoffs.

## Content


> **TL;DR** - You can run DeepSeek and Gemini inside the OpenAI Agents SDK by configuring an `AsyncOpenAI` client with custom base URLs and credentials. By wrapping these clients in `OpenAIChatCompletionsModel`, your agents gain full function-call compatibility across multiple LLM providers while cutting cloud API costs by up to 90 percent.


## Understanding Custom Provider Compatibility in the Agents SDK 🤖

When I first started building multi-agent workflows, I wanted a way to experiment with different LLM providers without rewriting my entire agent loop. The OpenAI Agents SDK makes this possible because it relies on standard OpenAI-compatible API schemas. By substituting default API endpoints with vendor-specific URLs, you can plug in DeepSeek, Google Gemini, or local models running on Ollama directly into your Python scripts.


![Custom provider compatibility in AI agents SDK and multi-model routing](Image)

How does the Agents SDK communicate with non-OpenAI models behind the scenes? It treats them as standard chat completion endpoints. Because these third-party providers mirror the OpenAI API shape, you can wrap your client using `OpenAIChatCompletionsModel` from the SDK. This guarantees that your agents can still execute tool calls, handle structured outputs, and maintain conversation state seamlessly across different providers.


## Setting Up AsyncOpenAI Clients for DeepSeek and Gemini ⚙️

Connecting custom models begins with initializing an `AsyncOpenAI` client configured with your provider-specific credentials and base URLs. For DeepSeek, you point your base URL to `https://api.deepseek.com`. For Gemini, you use the Google OpenAI-compatible endpoint at `https://generativelanguage.googleapis.com/v1beta/openai/`.


```python
import os
from openai import AsyncOpenAI
from agents import Agent, OpenAIChatCompletionsModel

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

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

Which environment variables do you need to export in your `.env` file? You should export `DEEPSEEK_API_KEY` and `GEMINI_API_KEY` alongside your core project variables. To prevent authentication errors, ensure your client instance is passed directly into the model wrapper for the specific agent you are building. You can explore detailed reference patterns in the OpenAI Agents SDK Model Documentation and review community setups in the LangDB Integration Guide.


## Delegating Tasks across Models with Multi-Agent Handoffs 💡

Multi-agent handoffs enable a central triage agent to pass user requests to specialized sub-agents powered by different LLMs. For instance, I often use a fast, inexpensive model like DeepSeek Chat for initial routing and data extraction, while delegating complex reasoning tasks to Gemini or Claude.

Why should you assign different tasks across model providers? Mixing models keeps workloads efficient while maximizing output quality. You do not need expensive frontier models for simple classification or formatting tasks. For complete multi-provider handoff examples, check out the guide on how to Build Agents with OpenAI SDK using any LLM Provider.


## Running Local DeepSeek Models via Ollama 🌐

If data privacy or offline processing is a top priority for your architecture, you can run DeepSeek locally using Ollama while maintaining full compatibility with the Agents SDK. Pointing your `AsyncOpenAI` client to your local gateway allows your agents to process queries securely on your own hardware without sending data to external cloud servers.


```python
# Initialize local Ollama client
local_client = AsyncOpenAI(
    api_key="ollama",  # Ollama requires a dummy string
    base_url="http://localhost:11434/v1"
)

local_agent = Agent(
    name="LocalAgent",
    model=OpenAIChatCompletionsModel(
        model="deepseek-r1:7b",
        openai_client=local_client
    )
)
```

Can you run high-performing reasoning models completely on your local machine? Yes, local execution gives you complete control over data privacy and eliminates cloud API costs entirely. For a complete local walkthrough, watch the OpenAI Agents SDK Local DeepSeek R1 Tutorial.


## Handling Telemetry 401 Errors and Tracing Limits 🚀

When running agents without an active OpenAI API key, the SDK built-in tracing utility may throw HTTP 401 telemetry errors because it attempts to authenticate against OpenAI's telemetry servers by default. You can resolve this by turning off tracing altogether using `set_tracing_disabled(True)`, or by setting an explicit tracing key using a valid OpenAI key from your platform dashboard.

Why does tracing fail when you rely solely on third-party API keys? The built-in telemetry client expects a valid OpenAI developer key for trace uploads. Review the OpenAI Developer Community Gemini Discussion to discover proven fixes for common connection hurdles and tracing adjustments.


## Bottom Line

Integrating DeepSeek and Gemini into the OpenAI Agents SDK is one of the most practical ways to build flexible, cost-effective AI workflows. By configuring custom `AsyncOpenAI` clients and wrapping them in `OpenAIChatCompletionsModel`, you retain full tool compatibility while choosing the ideal model for every specific task. For more details on structuring agent memory and tool calling, check out our guide on Postgres and S3 Memory Layers for AI Agents and our overview on Build Multi-Tool AI Agents with OpenAI Agents SDK and MCP.


## Sources

- Models - OpenAI Agents SDK (OpenAI)
- Use OpenAI Agents SDK with Gemini, Claude, DeepSeek (LangDB)
- Build Agents with OpenAI SDK using any LLM Provider (Medium)
- OpenAI Agents SDK Local DeepSeek R1 Local DeepSeek R1 + Ollama (YouTube)
- Using Gemini with OpenAI Agents SDK (OpenAI Developer Community)

## Frequently Asked Questions

### Can I use DeepSeek and Gemini with the OpenAI Agents SDK?

Yes. You can use DeepSeek and Gemini by configuring an AsyncOpenAI client with custom base URLs and passing it into OpenAIChatCompletionsModel within the OpenAI Agents SDK.

### How do I avoid tracing 401 errors when using non-OpenAI models?

Disable tracing using set_tracing_disabled(True) or provide an explicit OpenAI tracing key. The SDK telemetry client requires a valid OpenAI developer key for trace uploads.

### Can I run DeepSeek locally with the OpenAI Agents SDK?

Yes. You can run DeepSeek locally using Ollama. Point your AsyncOpenAI client base URL to http://localhost:11434/v1 and assign it to your agent using OpenAIChatCompletionsModel.

### Do DeepSeek and Gemini support multi-agent handoffs?

Yes. The OpenAI Agents SDK supports multi-agent handoffs across different LLM providers, allowing a triage agent to route queries to specialized sub-agents running DeepSeek or Gemini.

### Which model wrapper should I use for third-party providers?

Use OpenAIChatCompletionsModel. Most third-party LLM providers support the Chat Completions API schema, ensuring full compatibility with tools and function calls in the Agents SDK.

### How much money can switching to DeepSeek or Gemini save?

Switching background or specialized tasks from top-tier cloud models to DeepSeek or Gemini can reduce overall API costs by up to 90 percent.

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