1. API Usage
Token Oceans
  • Token Oceans User Manual
    • Register Account
    • Log In / Sign In
    • Purchase & Redeem
    • API Token
    • Playground - For Testing Only
  • API Usage
    • Api Docs
  1. API Usage

Api Docs

TokenOceans API Documentation / 接口文档#

Base URL: https://api.tokenoceans.com

Authentication / 认证#

All requests require an API Key in the header:
所有请求需在 Header 中携带 API Key:
Authorization: Bearer sk-xxxxxxxxxxxxxxxx

1. OpenAI Chat Completions#

Endpoint / 接口信息#

Item / 项目Value / 说明
Path / 路径/v1/chat/completions
Method / 方法POST
Content-Typeapplication/json

Request Parameters / 请求参数#

Parameter / 参数Type / 类型Required / 必填Description / 说明
modelstringYes / 是Model name, e.g. deepseek-v4-flash, deepseek-v4-pro, qwen3.6-plus / 模型名称
messagesarrayYes / 是List of conversation messages / 对话消息列表
streambooleanNo / 否Enable streaming output, default false / 是否流式输出
temperaturenumberNo / 否Sampling temperature, range 0-2, default 1 / 采样温度
top_pnumberNo / 否Nucleus sampling, range 0-1, default 1 / 核采样参数
max_tokensintegerNo / 否Maximum tokens to generate / 最大生成 token 数
frequency_penaltynumberNo / 否Frequency penalty, range -2 to 2, default 0 / 频率惩罚
presence_penaltynumberNo / 否Presence penalty, range -2 to 2, default 0 / 存在惩罚
stopstring/arrayNo / 否Stop sequences / 停止生成的标记
nintegerNo / 否Number of completions to generate, default 1 / 生成回复数量
toolsarrayNo / 否Available tools/functions / 可用工具列表
tool_choicestring/objectNo / 否Tool calling strategy / 工具调用策略
response_formatobjectNo / 否Response format, e.g. {"type": "json_object"} / 响应格式

Message Structure / messages 结构#

Field / 字段Type / 类型Required / 必填Description / 说明
rolestringYes / 是Role: system, user, assistant, tool / 角色
contentstring/arrayYes / 是Message content, supports text or multimodal array / 消息内容
namestringNo / 否Participant name / 参与者名称
tool_callsarrayNo / 否Tool calls (assistant messages) / 工具调用
tool_call_idstringNo / 否Tool call ID (tool messages) / 工具调用 ID

Multimodal Content / 多模态内容#

When content is an array / 当 content 为数组时:
{
  "role": "user",
  "content": [
    {"type": "text", "text": "What is in this image?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/image.png"}}
  ]
}

Request Example (Non-streaming) / 请求示例(非流式)#

Response Example (Non-streaming) / 响应示例(非流式)#

{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "created": 1700000000,
  "model": "deepseek-v4-pro",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Hello! I'm an AI assistant that can help you with questions, writing, coding, and various other tasks. How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 42,
    "total_tokens": 67
  }
}

Request Example (Streaming) / 请求示例(流式)#

Response Example (Streaming SSE) / 响应示例(流式 SSE)#

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"qwen3.6-plus","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"qwen3.6-plus","choices":[{"index":0,"delta":{"content":"Spring"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"qwen3.6-plus","choices":[{"index":0,"delta":{"content":" breeze"},"finish_reason":null}]}

data: {"id":"chatcmpl-abc123","object":"chat.completion.chunk","created":1700000000,"model":"qwen3.6-plus","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

Tool Calling Example / 工具调用示例#

Request / 请求:
{
  "model": "qwen3.6-plus",
  "messages": [
    {"role": "user", "content": "What's the weather like in Beijing today?"}
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather information for a specified city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {"type": "string", "description": "City name"}
          },
          "required": ["city"]
        }
      }
    }
  ]
}
Response / 响应:
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": null,
        "tool_calls": [
          {
            "id": "call_abc123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"city\": \"Beijing\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ]
}

2. Anthropic Messages#

Endpoint / 接口信息#

Item / 项目Value / 说明
Path / 路径/apps/anthropic
Method / 方法POST
Content-Typeapplication/json

Request Headers / 请求头#

HeaderRequired / 必填Description / 说明
AuthorizationYes / 是Bearer sk-xxxxxxxxxxxxxxxx
anthropic-versionNo / 否API version, e.g. 2023-06-01 / API 版本

Request Parameters / 请求参数#

Parameter / 参数Type / 类型Required / 必填Description / 说明
modelstringYes / 是Model name, e.g. qwen3.5-plus, qwen3.6-plus / 模型名称
messagesarrayYes / 是List of conversation messages / 对话消息列表
max_tokensintegerYes / 是Maximum tokens to generate / 最大生成 token 数
streambooleanNo / 否Enable streaming output, default false / 是否流式输出
systemstring/arrayNo / 否System prompt / 系统提示词
temperaturenumberNo / 否Sampling temperature, range 0-1, default 1 / 采样温度
top_pnumberNo / 否Nucleus sampling / 核采样参数
top_kintegerNo / 否Top-K sampling / Top-K 采样参数
stop_sequencesarrayNo / 否Stop sequences / 停止序列列表
toolsarrayNo / 否Available tools / 可用工具列表
tool_choiceobjectNo / 否Tool calling strategy / 工具调用策略
metadataobjectNo / 否Request metadata / 请求元数据

Message Structure / messages 结构#

Field / 字段Type / 类型Required / 必填Description / 说明
rolestringYes / 是Role: user or assistant / 角色
contentstring/arrayYes / 是Message content, supports text or content block array / 消息内容

Content Block Types / 内容块类型#

Text block / 文本块:
{"type": "text", "text": "Hello"}
Image block (Base64) / 图片块(Base64):
{
  "type": "image",
  "source": {
    "type": "base64",
    "media_type": "image/png",
    "data": "iVBORw0KGgo..."
  }
}
Image block (URL) / 图片块(URL):
{
  "type": "image",
  "source": {
    "type": "url",
    "url": "https://example.com/image.png"
  }
}

Request Example (Non-streaming) / 请求示例(非流式)#

Response Example (Non-streaming) / 响应示例(非流式)#

{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "`qwen3.6-plus",
  "content": [
    {
      "type": "text",
      "text": "Hello! I'm qwen3.6-plus, an AI assistant developed by Anthropic. I can help you with various tasks including answering questions, writing, analysis, coding, and more. How can I assist you today?"
    }
  ],
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "usage": {
    "input_tokens": 20,
    "output_tokens": 58
  }
}

Request Example (Streaming) / 请求示例(流式)#

Response Example (Streaming SSE) / 响应示例(流式 SSE)#

event: message_start
data: {"type":"message_start","message":{"id":"msg_abc123","type":"message","role":"assistant","model":"qwen3.6-plus","content":[],"stop_reason":null,"usage":{"input_tokens":15,"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":"Spring"}}

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

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":35}}

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

Tool Calling Example / 工具调用示例#

Request / 请求:
{
  "model": "qwen3.6-plus",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "What's the weather like in Beijing today?"}
  ],
  "tools": [
    {
      "name": "get_weather",
      "description": "Get weather information for a specified city",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {"type": "string", "description": "City name"}
        },
        "required": ["city"]
      }
    }
  ]
}
Response / 响应:
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "model": "qwen3.6-plus",
  "content": [
    {
      "type": "tool_use",
      "id": "toolu_abc123",
      "name": "get_weather",
      "input": {"city": "Beijing"}
    }
  ],
  "stop_reason": "tool_use",
  "usage": {
    "input_tokens": 120,
    "output_tokens": 45
  }
}
Submit Tool Result / 提交工具结果:
{
  "model": "qwen3.6-plus",
  "max_tokens": 1024,
  "messages": [
    {"role": "user", "content": "What's the weather like in Beijing today?"},
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_abc123",
          "name": "get_weather",
          "input": {"city": "Beijing"}
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "tool_use_id": "toolu_abc123",
          "content": "Beijing today: sunny, 22°C, light breeze"
        }
      ]
    }
  ]
}

3. Error Responses / 错误响应#

OpenAI Format / OpenAI 格式#

{
  "error": {
    "message": "Invalid API key provided",
    "type": "invalid_request_error",
    "param": null,
    "code": "invalid_api_key"
  }
}

Anthropic Format / Anthropic 格式#

{
  "type": "error",
  "error": {
    "type": "authentication_error",
    "message": "Invalid API key"
  }
}

Common Error Codes / 常见错误码#

HTTP Status / 状态码Description / 说明
400Bad Request — Invalid parameters / 请求参数错误
401Unauthorized — Invalid API Key / 认证失败
403Forbidden — Insufficient permissions / 权限不足
404Not Found — Endpoint does not exist / 接口不存在
429Too Many Requests — Rate limit exceeded / 请求频率超限
500Internal Server Error / 服务器内部错误
502Bad Gateway — Upstream service unavailable / 上游服务不可用
503Service Unavailable / 服务暂时不可用

4. SDK Examples / SDK 使用示例#

Python (OpenAI SDK)#

Python (Anthropic SDK)#

Node.js (OpenAI SDK)#

Node.js (Anthropic SDK)#

修改于 2026-05-15 03:40:32
上一页
Playground - For Testing Only
Built with