Skip to content

[BUG] bailian provider missing from envMap causes HTTP 401 when using __env__:BAILIAN_API_KEY #42858

@fdenny11gg

Description

@fdenny11gg

Bug Description

When configuring the Bailian (阿里云百炼) provider with environment variable reference "apiKey": "__env__:BAILIAN_API_KEY", the agent fails with HTTP 401: invalid access token or token expired error, even though:

  • The API key is valid and working when tested directly
  • The environment variable is correctly loaded by the systemd service
  • Other providers (minimax, nvidia, deepseek) work fine with the same pattern

Steps to Reproduce

  1. Configure ~/.config/openclaw/credentials.env with:

    BAILIAN_API_KEY=sk-sp-xxxxxxxxxxxxx
  2. Configure ~/.openclaw/openclaw.json with:

    {
      "models": {
        "providers": {
          "bailian": {
            "baseUrl": "https://coding.dashscope.aliyuncs.com/v1",
            "apiKey": "__env__:BAILIAN_API_KEY",
            "api": "openai-completions"
          }
        }
      }
    }
  3. Restart the Gateway and send a message using bailian/qwen3.5-plus model

  4. Check logs: HTTP 401: invalid access token or token expired

Root Cause

The envMap in the OpenClaw codebase does not include a mapping for the bailian provider. When resolveEnvApiKey("bailian") is called, it returns null because bailian is not in the mapping table.

Proposed Fix

Add bailian to the envMap in /src/agents/model-auth.ts:

const envMap = {
  // ... existing mappings
  bailian: "BAILIAN_API_KEY",
}

Environment

  • OpenClaw Version: 2026.3.8
  • Node.js: v22.22.0
  • OS: Linux 6.1.0-22-amd64 (x64)
  • Provider: Bailian (阿里云百炼)

Additional Context

  • Other providers (minimax, nvidia, deepseek) work correctly with the same __env__: pattern
  • Direct API calls to Bailian work fine with the same API key
  • This is a simple mapping omission that can be fixed by adding one line to envMap

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