TokenPlus

创建对话请求(OpenAI)

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

POST
/chat/completions

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

Authorization

AuthorizationBearer <token>

添加 Header Authorization: Bearer {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

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

{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "created": 1710000000,
  "model": "deepseek-chat",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "TokenPlus 是一个多模型网关,可以用统一接口连接不同模型供应商。"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 18,
    "total_tokens": 42
  }
}

{
  "error": {
    "message": "The request contains an invalid parameter value.",
    "code": 400,
    "metadata": {
      "error_type": "invalid_request"
    }
  }
}
{
  "error": {
    "message": "The provided TokenPlus API key is invalid, disabled, or expired.",
    "code": 401
  }
}
{
  "error": {
    "message": "Account has insufficient funds for the requested model.",
    "code": 402,
    "metadata": {
      "error_type": "insufficient_funds"
    }
  }
}

{
  "error": {
    "message": "Account spending is blocked.",
    "code": 403,
    "metadata": {
      "error_type": "account_spending_blocked"
    }
  }
}

{
  "error": {
    "message": "models \"unknown-model\" are not configured",
    "code": 404,
    "metadata": {
      "error_type": "model_not_found"
    }
  }
}
{
  "error": {
    "message": "The upstream provider rejected the request because a required precondition was not satisfied.",
    "code": 412,
    "metadata": {
      "error_type": "precondition_failed"
    }
  }
}
{
  "error": {
    "message": "The request payload exceeds TokenPlus's maximum allowed size.",
    "code": 413
  }
}
{
  "error": {
    "message": "The upstream provider received a syntactically valid request but could not process it.",
    "code": 422,
    "metadata": {
      "error_type": "unprocessable"
    }
  }
}

{
  "error": {
    "message": "The upstream provider rate limited the request.",
    "code": 429,
    "metadata": {
      "error_type": "rate_limit_exceeded"
    }
  }
}

{
  "error": {
    "message": "An internal server error occurred.",
    "code": 500
  }
}
{
  "error": {
    "message": "The upstream provider is unavailable or returned an invalid response.",
    "code": 502,
    "metadata": {
      "error_type": "provider_unavailable"
    }
  }
}

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

{
  "error": {
    "message": "The upstream provider did not respond before the request timed out.",
    "code": 504
  }
}