Skip to content

invalid_request_error when using "chat_completions" with triage agent (gemini -> any other model) #237

Closed

Description

@kmariunas

Describe the question

openai.BadRequestError: Error code: 400 - {'error': {'code': 'invalid_request_error', 'message': "messages.1.content.1.tool_use.id: String should match pattern '^[a-zA-Z0-9_-]+$'", 'type': 'invalid_request_error', 'param': None}}

I get this error when one agent passes it's tool usage info and other stuff to my anthropic agent.

I see that the input looks like this: [{'content': 'Please search for my memory about smart cities', 'role': 'user'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': '\n', 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': '', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': '', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}], and the fake ids are converted to empty strings afterwards, am i doing something wrong?

Debug information

  • Agents SDK version: (e.g. v0.0.4)
  • Python version (e.g. Python 3.12)

Repro steps

Ideally provide a minimal python script that can be run to reproduce the issue.


async def main_reproduce():
    set_default_openai_api("chat_completions")
    anthropic = AsyncOpenAI(
            api_key="",
            base_url="https://api.anthropic.com/v1/"
        )
    gemini = AsyncOpenAI(
            api_key="",
            base_url="https://generativelanguage.googleapis.com/v1beta/openai/"
        )

    gen_agent = Agent(
            name="General Chat Agent",
            instructions="provide a response and use tools",
            model=OpenAIChatCompletionsModel(model="claude-3-5-sonnet-20241022", openai_client=anthropic),
            handoff_description="general",
        )
    
    triage = Agent(
            name="Handoff agent",
            instructions="choose the correct agent to respond",
            model=OpenAIChatCompletionsModel(model="gemini-2.0-flash-001", openai_client=gemini),
            handoffs=[gen_agent]
        )
    result = await Runner.run(triage, "Help me remember the past month")
    print(result.final_output)


asyncio.run(main_reproduce())

Expected behavior

A clear and concise description of what you expected to happen.

Activity

  1. added
    bug
    on Mar 19, 2025
  2. kmariunas commented on Mar 19, 2025

    @kmariunas
    Author

    using two gemini models works, even though the input_list still has empty call_id ids
    {'content': 'Help me remember the past month', 'role': 'user'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': '', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': '', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}, {'id': '__fake_id__',

  3. kmariunas commented on Mar 19, 2025

    @kmariunas
    Author

    Using two anthropic models works as well, they generate 'call_id' value

    [{'content': 'Help me remember the past month', 'role': 'user'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': "I'll help you transfer to the General Chat Agent who can assist with recalling and discussing past events.", 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}, {'id': '__fake_id__', 'arguments': '{}', 'call_id': 'toolu_0166CqqT3JEj3XXFCqSRp2QM', 'name': 'transfer_to_general_chat_agent', 'type': 'function_call'}, {'call_id': 'toolu_0166CqqT3JEj3XXFCqSRp2QM', 'output': "{'assistant': 'General Chat Agent'}", 'type': 'function_call_output'}, {'id': '__fake_id__', 'content': [{'annotations': [], 'text': "I aim to help, but I should note that I don't have access to your personal memories or experiences from the past month. To help you remember, I can:\n\n1. Ask you questions about specific aspects you want to recall\n2. Help you walk through the timeline of the past month \n3. Discuss major public events that happened during that time\n\nWhat specifically would you like to remember about the past month? I can guide our conversation from there.", 'type': 'output_text'}], 'role': 'assistant', 'status': 'completed', 'type': 'message'}]

  4. changed the title [-]invalid_request_error when using "chat_completions" with triage agent[/-] [+]invalid_request_error when using "chat_completions" with triage agent (gemini -> any other model)[/+] on Mar 19, 2025
  5. rm-openai commented on Mar 19, 2025

    @rm-openai
    Collaborator

    Yeah looks like this is an issue with Gemini. Specifically, when I ran this curl snippet: https://ai.google.dev/gemini-api/docs/openai#function-calling

    The response has empty IDs for the tool call:

    {"choices":[{"finish_reason":"tool_calls","index":0,"message":{"role":"assistant","tool_calls":[{"function":{"arguments":"{\"location\":\"Chicago, IL\"}","name":"get_weather"},"id":"","type":"function"}]}}],"created":1742394406,"model":"gemini-2.0-flash","object":"chat.completion","usage":{"completion_tokens":7,"prompt_tokens":41,"total_tokens":48}}
    

    That is incompatible with openai, anthropic etc.

    I'm not totally sure how to work around this - any suggestions?

  6. kmariunas commented on Mar 19, 2025

    @kmariunas
    Author

    Maybe for gemini specifically it would be possible to replace call_id with some random id? Feels hacky, but would be really nice to have all of the models available for agents 🙏

  7. kmariunas commented on Mar 27, 2025

    @kmariunas
    Author

    hey, any updates on ths?

  8. moseshu commented on May 1, 2025

    @moseshu

    I got this error: Error code: 404 - {'type': 'error', 'error': {'type': 'not_found_error', 'message': 'Not Found'}}
    how to solve it?

  9. deleted a comment from on Jul 26, 2025
  10. seratch commented on Sep 22, 2025

    @seratch
    Member

    Thanks for sharing this and we're sorry for our slow response here.

    Non-OpenAI models often aren't fully compatible with OpenAIChatCompletionsModel even thought those platforms say they're compatible. Our latest recommendation is to use LiteLLM as the adapter for those platforms rather than trying to use OpenAIResponsesModel / OpenAIChatCompletionsModel with different model names and endpoints: https://openai.github.io/openai-agents-python/models/litellm/

    Even though LiteLLM does great job for the interoperability, some models may not fully support some features this SDK provides (e.g., Gemini models do not allow tools and structured outputs at a time). That said, for simple use cases, LiteLLM provides seamless integration.

    Let us close this issue now, but if you encounter any issues with LiteLLM, please feel free to open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfeature:chat-completions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions