Skip to content

API Reference

Overview

  • Base URL: https://open.dieyuyun.com
  • Authentication: Bearer Token or x-api-key header (get your API Key from the console)
  • Protocol: HTTPS

Chat Completions

Text generation endpoint with multi-turn conversation and streaming support.

Request

POST /v1/chat/completions

Parameters

ParameterTypeRequiredDescription
modelstringYesModel code, e.g. deepseek-v4-flash
messagesarrayYesMessage list
messages.rolestringYesRole: system, user, assistant
messages.contentstringYesMessage content
temperaturenumberNoTemperature, 0-2, default 1
max_tokensintegerNoMax tokens to generate
top_pnumberNoTop-p sampling, 0-1, default 1
streambooleanNoEnable streaming, default false

Request Example

json
{
  "model": "deepseek-v4-flash",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Hello!" }
  ],
  "temperature": 0.7,
  "max_tokens": 1024
}

Response

json
{
  "id": "chatcmpl-xxx",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "deepseek-v4-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 10,
    "total_tokens": 30
  }
}

Streaming

Set stream: true to receive Server-Sent Events:

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"delta":{"content":"!"},"finish_reason":null}]}

data: [DONE]

The last chunk in a streaming response includes a usage field for token statistics.

Messages (Anthropic Compatible)

Anthropic Messages API compatible endpoint for text generation. Use the Anthropic SDK to call directly.

Request

POST /v1/messages

Authentication

Two methods are supported:

  • x-api-key: <your-api-key> (recommended, default for Anthropic SDK)
  • Authorization: Bearer <your-api-key>

Parameters

ParameterTypeRequiredDescription
modelstringYesModel code, e.g. deepseek-v4-flash
messagesarrayYesMessage list
messages.rolestringYesRole: user, assistant
messages.contentstring/arrayYesMessage content, supports string or content blocks
systemstring/arrayNoSystem prompt, supports string or content blocks
max_tokensintegerYesMax tokens to generate
temperaturenumberNoTemperature, 0-1, default 1
top_pnumberNoTop-p sampling, 0-1, default 1
streambooleanNoEnable streaming, default false
stop_sequencesarrayNoList of stop sequences

Request Example

json
{
  "model": "deepseek-v4-flash",
  "max_tokens": 1024,
  "system": "You are a helpful assistant.",
  "messages": [{ "role": "user", "content": "Hello!" }]
}

Using the Anthropic Python SDK:

python
import anthropic

client = anthropic.Anthropic(
    base_url="https://open.dieyuyun.com",
    api_key="your-api-key"
)

message = client.messages.create(
    model="deepseek-v4-flash",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)
print(message.content[0].text)

Response

json
{
  "id": "msg_xxx",
  "type": "message",
  "role": "assistant",
  "model": "deepseek-v4-flash",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "usage": {
    "input_tokens": 10,
    "output_tokens": 10
  }
}

Streaming

Set stream: true to receive Server-Sent Events. The event sequence is:

event: message_start
data: {"type":"message_start","message":{"id":"msg_xxx","type":"message","role":"assistant","model":"deepseek-v4-flash","stop_reason":null,"usage":{"input_tokens":10,"output_tokens":0}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"!"}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn"},"usage":{"output_tokens":10}}

event: message_stop
data: {"type":"message_stop"}

finish_reason Mapping

Anthropic stop_reasonOpenAI finish_reasonDescription
end_turnstopNormal stop
max_tokenslengthMax tokens hit

Search Completions

Web search endpoint that generates answers based on real-time search results.

Request

POST /v1/search/completions

Parameters

ParameterTypeRequiredDescription
modelstringYesModel code that supports search
messagesarrayYesMessage list, same as Chat Completions
streambooleanNoEnable streaming, default false

Request Example

json
{
  "model": "deepseek-v4-flash",
  "messages": [{ "role": "user", "content": "What are today's tech news?" }]
}

Response

The response format is the same as Chat Completions, with search source citations included in the answer.

Images Generations

Generate images from text descriptions.

Request

POST /v1/images/generations

Parameters

ParameterTypeRequiredDescription
modelstringYesImage generation model code
promptstringYesText description of the image
nintegerNoNumber of images to generate, default 1
sizestringNoImage size, e.g. 1024x1024
response_formatstringNoResponse format: url (default) or b64_json

Request Example

json
{
  "model": "gpt-image-2",
  "prompt": "A white cat sitting on a windowsill",
  "n": 1,
  "size": "1024x1024"
}

Response

json
{
  "created": 1700000000,
  "data": [
    {
      "url": "https://cdn.wuliang.ai/images/xxx.png"
    }
  ]
}

Balance

Queries the available balance of the tenant that owns the current API Key, along with that Key's daily/monthly budget usage. Useful for "usage query" features in third-party tools like CC Switch.

Request

http
GET /v1/balance HTTP/1.1
Host: open.dieyuyun.com
Authorization: Bearer sk-xxxxxxxxxxxxxxxx

No query parameters, no request body.

Response

json
{
  "object": "balance",
  "currency": "CNY",
  "balance": 138.5,
  "api_key": {
    "id": "1923456789012345678",
    "name": "claude-code",
    "daily_budget": 20.0,
    "daily_used": 3.25,
    "daily_remaining": 16.75,
    "daily_reset_at": "2026-06-09T00:00:00+08:00",
    "monthly_budget": null,
    "monthly_used": null,
    "monthly_remaining": null,
    "monthly_reset_at": null
  }
}
FieldDescription
currencyFixed CNY.
balanceTotal available (yuan) = top-up balance + gift balance.
api_key.id / api_key.nameID and name of the current API Key.
api_key.daily_budgetPer-Key daily budget (yuan), null if not set.
api_key.daily_used / daily_remainingConsumed / remaining today (yuan).
api_key.daily_reset_atNext daily budget reset time (ISO8601).
api_key.monthly_*Monthly equivalents of the fields above.

See Connect CC Switch for full third-party tool configuration examples.

Error Codes

HTTP StatusCodeDescription
400INVALID_PARAMSInvalid request parameters
401UNAUTHORIZEDInvalid or expired API Key
403FORBIDDENAccess denied
404MODEL_NOT_FOUNDModel not found or offline
429RATE_LIMITRate limit exceeded
500INTERNAL_ERRORInternal server error
502UPSTREAM_ERRORUpstream model service error
504GATEWAY_TIMEOUTRequest timeout

All error responses use JSON format:

json
{
  "error": {
    "code": "RATE_LIMIT",
    "message": "Rate limit exceeded. Please retry after 60s.",
    "request_id": "req-xxx"
  }
}

Use request_id to trace issues in the console request logs.

Rate Limits

  • Default RPM (Requests Per Minute): 60
  • Default TPM (Tokens Per Minute): 100,000
  • Configurable per API Key in the console

When rate limited, a 429 status is returned with these response headers:

  • X-RateLimit-Limit: Total limit for the current window
  • X-RateLimit-Remaining: Remaining requests in the current window
  • Retry-After: Suggested retry wait time in seconds