Preface

Third-party AI programming tools (such as Claude Code, Cursor, and Windsurf) typically require OpenAI- or Anthropic-compatible API endpoints. If you have Trae Work CN credits or quota, you can use the DSH plugin dsh-trae-api to run a local proxy service that converts these credits into standard interfaces.

The plugin acts as a DeepSeek Harness (DSH) plugin (npm package name @casually/dsh-trae-api). It automatically starts the proxy service when the dsh process starts, and can also be run standalone.

Prerequisites

  1. Trae IDE is installed and you are logged in (supports Trae CN, TRAE SOLO CN, Trae SG, and TRAE SOLO).
  2. Node.js version >= 18.
  3. The globalStorage/storage.json file exists in the %APPDATA% directory for the corresponding IDE.

Installation and Enablement

It is recommended to install it through the DSH plugin manager.

# 安装到 web profile
dsh plugin --profile web add @casually/dsh-trae-api

# 重启 dsh 使插件生效
dsh web

After installation, the proxy service runs by default at http://localhost:9220.

Core Features

The plugin provides the following capabilities:

  • Automatic decryption of authentication data: Automatically decrypts the authentication token from the local storage.json file, supporting tc-encrypted and plaintext formats.
  • Compatible endpoints: Provides OpenAI (/v1/chat/completions) and Anthropic (/v1/messages) compatible interfaces.
  • Streaming output: Supports SSE streaming responses.
  • Tool calling support: Fully supports Claude Code tool calls.
  • Endpoint fallback mechanism: A 3-stage API endpoint fallback mechanism to improve stability.
  • Format adaptation: Automatically adapts to CN and SG SSE event formats.
  • Automatic token refresh: Automatically refreshes the token when it expires and writes it back to the .env file.
  • Context truncation: Automatically truncates context to avoid exceeding token limits.
  • Web settings page: Provides a DSH Web settings page supporting real-time status viewing, request statistics, token management, hot configuration updates, and more.

Usage Examples

Claude Code

$env:ANTHROPIC_BASE_URL = "http://localhost:9220"
$env:ANTHROPIC_API_KEY = "trae-local-api"
claude

Cursor

  • Base URL: http://localhost:9220/v1
  • API Key: trae-local-api
  • Model: Any model name (e.g., claude-sonnet-4-6, gpt-4o, auto)

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(base_url="http://localhost:9220/v1", api_key="trae-local-api")

response = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Configuration and Security

  • Default authentication: API Key authentication is enabled by default, with the default value trae-local-api.
  • Network restrictions: Listens on 127.0.0.1 by default, and CORS allows only localhost origins.
  • LAN access: To allow LAN access, set HOST=0.0.0.0 and also set a strong API_KEY.
  • Token management: Expired tokens are automatically refreshed and saved to .env; do not commit the .env file to version control.
  • Environment variables:
    • TRAE_EDITION: Trae edition (cn/solo/sg/solo-sg), default cn.
    • API_KEY: API key for this service, default trae-local-api.
    • PORT: Listening port, default 9220.
    • HOST: Listening address, default 127.0.0.1.

Notes

  • This tool is only effective if you already have Trae credits; it essentially consumes Trae API quota.
  • It is intended for learning and research purposes only; users are solely responsible for costs and compliance issues.
  • The default authentication configuration should be modified according to actual security requirements.