API Reference Documentation

Sanki API supports both OpenAI and Anthropic protocol formats. Choose the integration method that fits your needs.

Quick Start

Get started with the Sanki API in just three steps:

Create an Account
Register and log in on the Sanki platform
Get Your API Key
Create an API key on the API Keys page
Send a Request
Choose a protocol format and start calling

Base URLs

Sanki offers two protocol access methods. Choose the Base URL and auth method that matches your client:

OpenAI Compatible
https://api.sanki.ink/v1

Suitable SDK: openai (Python/Node/Go)

Auth Method: Authorization: Bearer <key>

Main Endpoint: /v1/chat/completions

Anthropic Compatible
https://api.sanki.ink/v1

Suitable SDK: @anthropic-ai/sdk / Claude Code

Auth Method: x-api-key: <key>

Main Endpoint: /v1/messages

Base URL Client Lookup Table

Different clients handle base_url differently: some use it as a complete prefix, while others append /v1 automatically. Using the wrong setting can cause double-prefix errors like /v1/v1/messages.

ClientBase URL to UseNote
OpenAI Python/Node SDKhttps://api.sanki.ink/v1SDK treats base_url as complete prefix, needs /v1
Anthropic Python/Node SDKhttps://api.sanki.ink/v1Same as above, needs /v1
Claude Code (ANTHROPIC_BASE_URL)https://api.sanki.ink/v1Without /v1; Claude Code auto-appends /v1/messages
Hermes Agent (custom_providers)https://api.sanki.inkWithout /v1; Hermes auto-appends /v1/messages
curlhttps://api.sanki.ink/v1/chat/completionsFull URL including /v1 and specific endpoint

Try It in One Minute

curl (OpenAI)
curl -X POST "https://api.sanki.ink/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMax-M3",
    "messages": [
      {"role": "user", "content": "Hello, Sanki!"}
    ]
  }'
curl (Anthropic)
curl -X POST "https://api.sanki.ink/v1/messages" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello, Sanki!"}
    ]
  }'

Authentication

Use different auth headers depending on the protocol. Create and manage your API Key on the API Keys page.

API Key Format Specification

The platform currently uses sk- prefixed, 64-character API Keys (prefix sk- + 61-char base62 random string):

text
sk-yt1zAiMnFWCH3OwAfwXZEMGRnIgLq1mxkxxUSlDaHgq3jOGTlSJUc6TPUuMzo
└sk─── 61 char base62 (A-Z a-z 0-9) ───────────────────────┘

⚠ Security Notice: The full key is displayed only once upon creation and cannot be viewed again after closing the panel. Copy or download the .txt backup immediately. The list shows only the first 12-character prefix (e.g., sk-yt1zAiMnF) for identification, not authentication.

⛔ Old Keys Deprecated: Legacy sk-sanki-* format (35-character) keys have all been forcibly revoked. Please regenerate new sk- prefixed keys.

OpenAI Protocol Authentication

http
Authorization: Bearer YOUR_API_KEY

Applies to /v1/chat/completions, /v1/models, and other OpenAI-compatible endpoints.

Anthropic Protocol Authentication

http
x-api-key: YOUR_API_KEY
anthropic-version: 2023-06-01
Important: The /v1/messages endpoint must use the x-api-key header and does NOT support Authorization: Bearer. This matches official Anthropic API behavior — the official SDK / Claude Code / Hermes (anthropic mode) uses x-api-key by default with no additional configuration needed. If you see 401 missing x-api-key header, check if you are mistakenly using a Bearer header.

Chat Completions (OpenAI)

Standard OpenAI-compatible Chat Completions endpoint. Given a list of conversation messages, the model returns a response.

POST/v1/chat/completions

Request Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID, e.g., gpt-4o, claude-sonnet-4-6, gemini-2.5-pro
messagesarrayYesMessage list, each containing role (system/user/assistant/tool) and content
temperaturenumberNoSampling temperature 0-2, default 1. Higher values produce more randomness.
top_pnumberNoNucleus sampling parameter 0-1, default 1
max_tokensintegerNoMaximum number of tokens to generate
streambooleanNoEnable SSE streaming responses, default false
toolsarrayNoList of function calling tool definitions

Request Example

curl
curl -X POST "https://api.sanki.ink/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMax-M3",
    "messages": [
      {"role": "system", "content": "你是专业的 AI 助手"},
      {"role": "user", "content": "解释量子计算"}
    ],
    "temperature": 0.7,
    "max_tokens": 1024
  }'
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.sanki.ink/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.choices[0].message.content)

Response Format

json
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "MiniMax-M3",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 9,
    "total_tokens": 19
  }
}

Messages (Anthropic)

Anthropic Messages API compatible endpoint. Supports direct integration with tools like Claude Code via /v1/messages.

POST/v1/messages

Choose the Base URL by client

https://api.sanki.ink/v1Anthropic SDK (Python / TypeScript) — the SDK appends /messages automatically
https://api.sanki.inkClaude Code — appends /v1/messages automatically; use the root path

Request Parameters

ParameterTypeRequiredDescription
modelstringYesModel ID, e.g., gpt-4o, claude-sonnet-4-6, gemini-2.5-pro
messagesarrayYesMessage list, each containing role (user/assistant) and content
max_tokensintegerYesMaximum number of tokens to generate
systemstring | arrayNoSystem prompt, can be a string or array of content blocks
temperaturenumberNoSampling temperature 0-1, default 1
top_pnumberNoNucleus sampling parameter 0-1, default 1
toolsarrayNoList of function calling tool definitions

Request Example

curl
curl -X POST "https://api.sanki.ink/v1/messages" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek-v4-pro",
    "max_tokens": 1024,
    "system": "你是专业的 AI 助手",
    "messages": [
      {"role": "user", "content": "解释量子计算"}
    ]
  }'
python
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.sanki.ink/v1",
    api_key="YOUR_API_KEY"
)

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    system="你是专业的 AI 助手",
    messages=[
        {"role": "user", "content": "Hello!"}
    ]
)

print(response.content[0].text)

Response Format

json
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "deepseek-v4-pro",
  "content": [
    {
      "type": "text",
      "text": "Hello! How can I help you today?"
    }
  ],
  "usage": {
    "input_tokens": 10,
    "output_tokens": 9
  }
}

Responses API

OpenAI Responses API 兼容端点,支持字符串和数组两种 input 格式。

POST/v1/responses

Request Example

curl
curl -X POST "https://api.sanki.ink/v1/responses" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "input": "解释量子计算的基本原理",
    "max_output_tokens": 1024
  }'

Image Generation

支持 DALL·E、Wan 等图片生成模型,返回生成图片的 URL。

POST/v1/images/generations

Request Example

curl
curl -X POST "https://api.sanki.ink/v1/images/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seedream-4-0-250828",
    "prompt": "a cat sitting on a cloud",
    "n": 1,
    "size": "1024x1024"
  }'

Response Format

json
{
  "created": 1720000000,
  "data": [
    {
      "url": "https://...",
      "revised_prompt": "A detailed illustration of..."
    }
  ]
}

Video Generation

支持 Kling、Wan 等视频生成模型。视频生成是异步任务,提交后返回 task_id,通过查询接口获取结果。

POST/v1/videos/generations

Request Example

curl
curl -X POST "https://api.sanki.ink/v1/videos/generations" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling-v1",
    "prompt": "a sunset over the ocean with waves",
    "duration": 5,
    "size": "1920x1080"
  }'
json
{
  "task_id": "task_abc123",
  "status": "processing",
  "message": "Video generation started"
}
GET/v1/videos/:task_id

查询视频任务状态和结果。

curl
curl "https://api.sanki.ink/v1/videos/task_abc123" \
  -H "Authorization: Bearer YOUR_API_KEY"
json
{
  "task_id": "task_abc123",
  "status": "completed",
  "video_url": "https://...",
  "duration": 5,
  "size": "1920x1080"
}

Streaming (SSE)

Both protocols support Server-Sent Events (SSE) streaming. Enable by setting the corresponding parameters:

OpenAI Streaming

Set stream: true to receive data: prefixed SSE events.

curl
curl -X POST "https://api.sanki.ink/v1/chat/completions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MiniMax-M3",
    "messages": [{"role": "user", "content": "讲个故事"}],
    "stream": true
  }'
data: {"choices":[{"delta":{"content":"从"}}]}
data: {"choices":[{"delta":{"content":"前"}}]}
data: {"choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]

Models

GET/v1/models

List all available models and their information. Authentication header required.

curl (OpenAI)
curl "https://api.sanki.ink/v1/models" \
  -H "Authorization: Bearer YOUR_API_KEY"

Error Codes

ParameterTypeRequiredDescription
400Bad RequestNoBad Request — missing required fields or invalid format
401UnauthorizedNoUnauthorized — API Key is invalid or expired
402Payment RequiredNoPayment Required — insufficient balance, please recharge and retry
403ForbiddenNoForbidden — no permission to access this resource
404Not FoundNoNot Found — resource does not exist
429Too Many RequestsNoToo Many Requests — rate limit exceeded, please retry later
500Internal Server ErrorNoInternal Server Error — please retry later or contact support
503Service UnavailableNoService Unavailable — upstream model may be overloaded

Error Response Example

json
{
  "error": {
    "type": "insufficient_quota",
    "message": "余额不足,当前余额 ¥0.50,本次调用需要 ¥0.15",
    "code": 402
  }
}

Rate Limits

To ensure platform stability, the Sanki API enforces rate limits. A 429 status code is returned when limits are exceeded.

Free Plan
10 RPM
10,000 TPM
Basic Plan
60 RPM
100,000 TPM
Pro Plan
300 RPM
1,000,000 TPM

RPM = Requests Per Minute, TPM = Tokens Per Minute. Upgrade your plan for higher limits.

SDKs

The Sanki API is fully compatible with the official OpenAI / Anthropic SDKs. Simply change the base_url to get started.

Python (OpenAI SDK)

bash
pip install openai
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.sanki.ink/v1",
    api_key="YOUR_API_KEY"
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)

Node.js (OpenAI SDK)

bash
npm install openai
javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.sanki.ink/v1',
  apiKey: 'YOUR_API_KEY',
});

const response = await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'Hello!' }],
});

console.log(response.choices[0].message.content);

Python (Anthropic SDK)

bash
pip install anthropic
python
from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.sanki.ink/v1",
    api_key="YOUR_API_KEY"
)

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.content[0].text)

Claude Code Configuration

To use Sanki with Claude Code, set the environment variables to point to the Sanki API:

bash
export ANTHROPIC_BASE_URL="https://api.sanki.ink/v1"
export ANTHROPIC_API_KEY="YOUR_SANKI_API_KEY"

Go (go-openai)

bash
go get github.com/sashabaranov/go-openai
go
package main

import (
    "context"
    "fmt"
    "github.com/sashabaranov/go-openai"
)

func main() {
    config := openai.DefaultConfig("YOUR_API_KEY")
    config.BaseURL = "https://api.sanki.ink/v1"
    client := openai.NewClientWithConfig(config)

    resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{
        Model: "deepseek-v4-pro",
        Messages: []openai.ChatCompletionMessage{
            {Role: "user", Content: "Hello!"},
        },
    })
    if err != nil {
        panic(err)
    }
    fmt.Println(resp.Choices[0].Message.Content)
}

Changelog

v2.62026-07
  • 新增图片生成 API (/v1/images/generations)
  • 新增视频生成 API (/v1/videos/generations)
  • 新增 Responses API (/v1/responses)
  • 新增计量规则体系(8 维 token + 图片/视频)
  • 销售价设置:支持按维度独立加价
  • 计量计价全链路优化
v2.52026-06
  • 生产环境深度优化
  • 断路器机制完善
  • 协议框架零转换原则落地
  • 新增 Gemini 协议入口
v2.22026-06-06
  • API Key upgraded to 64 characters (sk- + 61 char base62)
  • Fixed base_url double /v1 concatenation issue, added client lookup table
  • User Center API Key panel: show/hide toggle, multiple copy, download .txt backup
  • Legacy sk-sanki-* 35-char keys have been forcibly revoked
v2.12026-06
  • Added Anthropic Messages API inbound endpoint /v1/messages
  • Claude Code direct integration support
  • Updated multi-protocol API documentation
v2.02026-05
  • New unified API gateway launched
  • OpenAI-compatible protocol support
  • Added Model Square and Rankings
  • Improved trilingual i18n support
v1.02025-12
  • Platform officially launched
  • Basic Chat Completions endpoint
  • API Key management and usage statistics

Still have questions? Visit the Console to get your API Key, or check out the Model Square to explore available models.

客服
Support

检测到您的浏览器使用中文,要切换到中文版吗?