#Is Openrouter compatible with Openais agent sdk?

7 messages · Page 1 of 1 (latest)

umbral iris
#

Trying to use qwen via Cerebras through Open Router and the tool calls seem to be in a different format than the typsecript agent sdk expects

https://openai.github.io/openai-agents-js/

This is how I try to get it working and I am getting responses just the tool calls are not executed (If I don't use a custom model it works).

return new Agent({
    name: config.name,
    instructions: systemPrompt,
    tools: tools,
    model: new OpenAIChatCompletionsModel(
      new Cerebras({
        apiKey: process.env.OPENROUTER_API_KEY,
        baseURL: "https://openrouter.ai/api"
     }) as unknown as OpenAI,
     'qwen/qwen3-235b-a22b-2507',
    ),
    modelSettings: {
      parallelToolCalls: false,
      providerData: {
        provider: {
          only: ["Cerebras"]
       }
      },
    },
  });
OpenAI Agents SDK

The OpenAI Agents SDK for TypeScript enables you to build agentic AI apps in a lightweight, easy-to-use package with very few abstractions.

zenith bobcatBOT
#

OpenRouter supports Qwen models via Cerebras, but the tool call format may differ from what the OpenAI Agents TypeScript SDK expects, causing tool calls to not execute properly when using custom models like 'qwen/qwen3-235b-a22b-2507'. This model is optimized for agent workflows but might require adapting the SDK's tool call handling to match the provider's response format.

To resolve this:

  • Verify the response format from the Cerebras provider matches the SDK's expected structure.
  • Check if the SDK allows customizing or extending tool call parsing for non-OpenAI models.
  • Consider using an adapter layer to translate Cerebras responses into the SDK's expected format.

OpenRouter normalizes some requests but provider-specific differences can affect tool call execution with custom models. More details on Cerebras Qwen models are available here: Cerebras | OpenRouter and model info here: Qwen | OpenRouter.

Are you looking to run agent tool calls with heavy reasoning models or simpler instruction-following tasks?

-# This is an automated response. Use !mute to stop the bot from responding.

Browse models provided by Cerebras

OpenRouter

The unified interface for LLMs. Find the best models & prices for your prompts

umbral iris
#

For reference this is waht I get back on Openrouter if I enable debug logging:

Response received: {
   "id": "gen-1754387096-4GQzYnoSieNOrNpzuUbt",
   "provider": "Cerebras",
   "model": "qwen/qwen3-235b-a22b-2507",
   "object": "chat.completion",
   "created": 1754387096,
   "choices": [
     {
       "logprobs": null,
       "finish_reason": "tool_calls",
       "native_finish_reason": "tool_calls",
       "index": 0,
       "message": {
         "role": "assistant",
         "content": "",
         "refusal": null,
         "reasoning": null,
         "tool_calls": [
           {
             "id": "b3e816fbe",
             "type": "function",
             "function": {
               "name": "navigate",
               "arguments": "{\"url\": \"https://www.google.com\", \"intent\": \"Search for Cerebras company website and employee location information\"}"
             },
             "index": 0
           }
         ]
       }
     }
   ],
   "system_fingerprint": "fp_3311bd499991eaae8353",
   "usage": {
     "prompt_tokens": 1722,
     "completion_tokens": 38,
     "total_tokens": 1760,
     "prompt_tokens_details": {
       "cached_tokens": 0
     }
   }
 }
zenith bobcatBOT
#

The OpenRouter response for your Qwen model includes a tool_calls array inside the assistant's message, which is different from the standard OpenAI Agents SDK expectation where tool calls may be embedded differently.

To integrate this with the OpenAI Agents TypeScript SDK, you likely need to adapt the SDK's tool call handling to parse the tool_calls field in the response message. The SDK may not natively support this tool_calls structure from the Cerebras Qwen provider.

Key points:

  • The response's finish_reason is "tool_calls", indicating tool execution is expected.
  • Tool calls appear under message.tool_calls with function.name and arguments as a JSON string.
  • The SDK needs to extract and execute these tool calls based on this format.

Check if the SDK allows customizing the parsing of the assistant's response to handle tool_calls explicitly, or create an adapter that converts tool_calls to the SDK's expected function call format.

Would you like help with adapting your TypeScript code to parse and run these tool_calls manually?

-# This is an automated response. Use !mute to stop the bot from responding.

umbral iris
#

If I use the openai api it looks way different with a longer response.
and the tool call nested in an output field?

Response received: {
   "id": "resp_6891d405ecbc8199a314a714c77d244609bf31f8e84507d7",
   "object": "response",
   "created_at": 1754387462,
   "status": "completed",
   "background": false,
   "error": null,
   "incomplete_details": null,
   "instructions": "...",
   "max_output_tokens": null,
   "max_tool_calls": null,
   "model": "gpt-4.1-2025-04-14",
   "output": [
     {
       "id": "fc_6891d406e7588199976aaec87a578bde09bf31f8e84507d7",
       "type": "function_call",
       "status": "completed",
       "arguments": "{\"url\":\"https://www.cerebras.net/\",\"intent\":\"Find employee or leadership team location details on Cerebras company website.\"}",
       "call_id": "call_0WRE1LkSz7l1fiCtNBh6r1CR",
       "name": "navigate"
     }
   ],
   "parallel_tool_calls": false,
   ...
 } ```

I don't think this should differ so much though, I thought everyone is trying to be OpenAI compatible. Am I using a wrong endpoint or something?
zenith bobcatBOT
#

Bot has reached the maximum number of messages for this thread.

umbral iris
#

If I use cerebras api directly (with a cerebras trial key) it works btw althought the response still looks different:

Response received: {
   "id": "chatcmpl-cb1906c7-184c-47d5-a585-cac374c6e782",
   "choices": [
     {
       "finish_reason": "tool_calls",
       "index": 0,
       "message": {
         "tool_calls": [
           {
             "id": "551e69562",
             "type": "function",
             "function": {
               "name": "get_page_content",
               "arguments": "{\"intent\": \"Identify the search input field on Google homepage\"}"
             }
           }
         ],
         "role": "assistant"
       }
     }
   ],
   "created": 1754387903,
   "model": "qwen-3-235b-a22b-instruct-2507",
   "system_fingerprint": "fp_3311bd499991eaae8353",
   "object": "chat.completion",
   "usage": {
     "prompt_tokens": 3375,
     "completion_tokens": 27,
     "total_tokens": 3402,
     "prompt_tokens_details": {
       "cached_tokens": 0
     }
   },
   "time_info": {
     "queue_time": 0.70255571,
     "prompt_time": 0.139157879,
     "completion_time": 0.035462362,
     "total_time": 0.8788118362426758,
     "created": 1754387903
   }
 }