#Completions API error 400 with Polaris Alpha

4 messages · Page 1 of 1 (latest)

oak marten
#

The error below happens every time I send the following payload, I think either because the provider has a bug or there's one in the Completions <-> Responses API conversion. I see that the default OpenRouter's chat interface uses Responses with the LLM, so it may be the cause. Haven't tested with other models.

{
    "error": {
        "message": "Provider returned error",
        "code": 400,
        "metadata": {
            "raw": "ERROR",
            "provider_name": "Stealth"
        }
    },
    "user_id": "user_xxx"
}
{
    "messages": [
        {
            "content": "Continue numbers",
            "role": "system"
        },
        {
            "content": "123",
            "role": "user"
        },
        {
            "content": null,
            "name": "number_agent",
            "role": "assistant",
            "tool_calls": [
                {
                    "type": "function",
                    "id": "777",
                    "function": {
                        "name": "start_file_agent",
                        "arguments": "{\"question\": \"What are the numbers available?\"}"
                    }
                }
            ]
        },
        {
            "content": "Some system string",
            "name": "number_agent_test_system",
            "role": "system"
        },
        {
            "content": "4, 5, 6",
            "role": "tool",
            "tool_call_id": "777"
        }
    ],
    "model": "openrouter/polaris-alpha",
    "stream": false
}
rich tideBOT
#

I'm an AI assistant - my answers may be incorrect and I cannot see screenshots. Please verify information with the OpenRouter docs.

To help debug this issue, I need a bit more information:

  • What is the exact API endpoint you're calling (full URL)?
  • Is this payload being sent to the Completions API, the Responses API, or something else?
  • Are you able to successfully call this endpoint with a simpler payload (e.g., just a user message, no tool calls or extra roles)?

These details will help pinpoint if the problem is with your payload, model, provider, or the Completions ⇄ Responses API mapping layer.

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

The author you are looking for could not be found.

oak marten
#

The fix is to swap the tool response message and the system one in places, like this:

{
    "messages": [
        {
            "content": "Continue numbers",
            "role": "system"
        },
        {
            "content": "123",
            "role": "user"
        },
        {
            "content": null,
            "name": "number_agent",
            "role": "assistant",
            "tool_calls": [
                {
                    "type": "function",
                    "id": "777",
                    "function": {
                        "name": "start_file_agent",
                        "arguments": "{\"question\": \"What are the numbers available?\"}"
                    }
                }
            ]
        },
        {
            "content": "4, 5, 6",
            "role": "tool",
            "tool_call_id": "777"
        },
        {
            "content": "Some system string",
            "name": "number_agent_test_system",
            "role": "system"
        }
    ],
    "model": "openrouter/polaris-alpha",
    "stream": false
}
{
    "id": "gen-xxx",
    "provider": "Stealth",
    "model": "openrouter/polaris-alpha",
    "object": "chat.completion",
    "choices": [
        {
            "logprobs": null,
            "finish_reason": "stop",
            "native_finish_reason": "stop",
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "127",
                "refusal": null,
                "reasoning": null
            }
        }
    ],
    "usage": {
        "prompt_tokens": 62,
        "completion_tokens": 10,
        "total_tokens": 72,
        "prompt_tokens_details": {
            "cached_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 0
        }
    }
}
rich tideBOT
#

Thank you for sharing your findings and the fix. Based on your message, the ordering of messages in the messages array is critical for valid tool use with OpenRouter's Completions API, especially for a model like openrouter/polaris-alpha.

Key points:

  • The tool response (role: "tool") must immediately follow the assistant's tool call that it completes.
  • Any system messages or other non-tool messages should come after the tool response in the message array.

This ordering aligns with the tool-calling requirements documented for OpenRouter-compatible APIs. As stated:

"The messages array should preserve conversation context and maintain correct sequence. After a model returns a tool call, your code should execute the tool, append the tool’s result with role: "tool", and only then proceed with further system or user messages."
Tool Calling Guide

Proper ordering ensures that conversation and tool context is preserved, enabling the model/provider to process your request without a 400 error.

Let me know if you need more technical details about tool-calling best practices or message formatting!

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