Skip to content

openai-completions API type does not support tool calling with third-party OpenAI-compatible APIs #41328

@MicahelWang

Description

@MicahelWang

Bug Description

When using third-party OpenAI-compatible APIs (like Alibaba Cloud Bailian/Qwen) with the `openai-completions` API type, tool calling does not work. The model outputs tool commands in text format (e.g., ```bash code blocks) instead of actually invoking the tools.

Steps to Reproduce

  1. Configure a third-party OpenAI-compatible API provider (e.g., Alibaba Cloud Bailian):
    ```json
    {
    "models": {
    "providers": {
    "bailian": {
    "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
    "apiKey": "your-api-key",
    "models": [
    {
    "id": "qwen3-coder-plus",
    "api": "openai-completions",
    "compat": {
    "supportsTools": true
    }
    }
    ]
    }
    }
    }
    }
    ```

  2. Run: `openclaw agent --agent main --local -m "Use exec tool to run echo test"`

  3. Observe that the model outputs ```bash exec --command="echo test"``` in text instead of actually calling the tool.

Verification

Direct curl request to Bailian API works correctly with tool calling:
```bash
curl -s "https://coding.dashscope.aliyuncs.com/v1/chat/completions"
-H "Authorization: Bearer $API_KEY"
-H "Content-Type: application/json"
-d '{
"model": "qwen3-coder-plus",
"messages": [{"role": "user", "content": "Check weather in Beijing"}],
"tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {...}}}]
}'
```
Returns: `"finish_reason":"tool_calls"` with proper tool call response.

Environment

  • OpenClaw: 2026.3.8 (3caab92)
  • Node.js: v24.14.0
  • Platform: Linux (WSL2)

Root Cause

The `openai-completions` API type does not properly send tool definitions to the model, even when `compat.supportsTools: true` is configured.

Suggested Fix

  1. Add a new API type `openai-chat` that explicitly uses `/v1/chat/completions` endpoint with proper tool calling support.
  2. Or fix `openai-completions` to properly handle tool definitions for OpenAI-compatible APIs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions