TokenPlus

创建对话请求(Anthropic)

根据给定的聊天对话创建模型响应。

POST
/messages

根据给定的聊天对话创建模型响应。

X-Api-Key<token>

添加 Header X-Api-Key: {API_KEY} 进行鉴权。

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/messages" \  -H "Content-Type: application/json" \  -d '{    "model": "deepseek-chat",    "models": [      "deepseek-chat-backup"    ],    "max_tokens": 1024,    "messages": [      {        "role": "user",        "content": "请用一句话介绍 TokenPlus。"      }    ]  }'

{
  "content": [
    {
      "type": "text",
      "text": "TokenPlus 是一个多模型网关,可以用统一接口连接不同模型供应商。"
    }
  ],
  "id": "msg_123",
  "model": "deepseek-chat",
  "role": "assistant",
  "stop_reason": "end_turn",
  "stop_sequence": null,
  "type": "message",
  "usage": {
    "input_tokens": 24,
    "output_tokens": 18
  }
}

{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "messages must be a non-empty array",
    "metadata": {
      "error_type": "invalid_request"
    }
  }
}
{
  "error": {
    "message": "The provided TokenPlus API key is invalid, disabled, or expired.",
    "code": 401
  }
}
{
  "type": "error",
  "error": {
    "type": "billing_error",
    "message": "Account has insufficient funds for the requested model.",
    "metadata": {
      "error_type": "insufficient_funds"
    }
  }
}

{
  "type": "error",
  "error": {
    "type": "permission_error",
    "message": "Account spending is blocked.",
    "metadata": {
      "error_type": "account_spending_blocked"
    }
  }
}

{
  "type": "error",
  "error": {
    "type": "not_found_error",
    "message": "models \"unknown-model\" are not configured",
    "metadata": {
      "error_type": "model_not_found"
    }
  }
}
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "The upstream provider rejected the request because a required precondition was not satisfied.",
    "metadata": {
      "error_type": "precondition_failed"
    }
  }
}
{
  "error": {
    "message": "The request payload exceeds TokenPlus's maximum allowed size.",
    "code": 413
  }
}
{
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "The upstream provider received a syntactically valid request but could not process it.",
    "metadata": {
      "error_type": "unprocessable"
    }
  }
}
{
  "type": "error",
  "error": {
    "type": "rate_limit_error",
    "message": "The upstream provider rate limited the request.",
    "metadata": {
      "error_type": "rate_limit_exceeded"
    }
  }
}
{
  "error": {
    "message": "An internal server error occurred.",
    "code": 500
  }
}
{
  "type": "error",
  "error": {
    "type": "api_error",
    "message": "The upstream provider is unavailable or returned an invalid response.",
    "metadata": {
      "error_type": "provider_unavailable"
    }
  }
}

{
  "type": "error",
  "error": {
    "type": "overloaded_error",
    "message": "The upstream provider is temporarily overloaded.",
    "metadata": {
      "error_type": "provider_overloaded"
    }
  }
}

{
  "type": "error",
  "error": {
    "type": "timeout_error",
    "message": "The upstream provider did not respond before the request timed out.",
    "metadata": {
      "error_type": "timeout"
    }
  }
}