Skip to content

400 BadRequestError with Gemini provider – Invalid JSON payload ("metadata" and "store" fields) #443

Closed
@Mubashar-Bashir

Description

@Mubashar-Bashir

Please read this first

  • Have you read the custom model provider docs, including the 'Common issues' section? ✅ Yes
  • Have you searched for related issues? ✅ Yes

Describe the question

I'm using the OpenAI Agents SDK with a custom model provider (Google Gemini via https://generativelanguage.googleapis.com/v1beta/openai/) and encountering a BadRequestError.

The Gemini API rejects the request with this error:

BadRequestError: Error code: 400 - [{'error': {'code': 400, 'message': 'Invalid JSON payload received. Unknown name "metadata": Cannot find field.\nInvalid JSON payload received. Unknown name "store": Cannot find field.'}}]

It appears that the Agents SDK is sending metadata and store fields automatically, but the Gemini API doesn't support these.


Debug information

  • Agents SDK version: v0.0.3
  • Python version: 3.11
  • Custom model provider: Google Gemini (Flash 1.5)/(Flash 2.0)
  • Request Type: chat.completions.create

Repro steps

Here’s a minimal script to reproduce the issue:

from openai import AsyncOpenAI
from agents import Agent, Runner, OpenAIChatCompletionsModel
from agents.run import RunConfig
import nest_asyncio

nest_asyncio.apply()

# External Async client for custom provider
client = AsyncOpenAI(
    api_key=google_api_key,
    base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
)

# Wrap client in SDK model
model = OpenAIChatCompletionsModel(
    model="gemini-1.5-flash",  # "gemini-2.0-flash"  
    openai_client=client,
)

config = RunConfig(
    model=model,
    model_provider=client,
    tracing_disabled=True
)

agent = Agent(name="Assistant", instructions="You are a helpful assistant")

# Run agent synchronously
result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)

**Metadata**
Please clarify:

Is there a way to prevent the SDK from sending unsupported fields like metadata or store?

Will future versions of the SDK provide better integration options for non-OpenAI endpoints?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions