跳转到主要内容
POST
/
chat
/
completions
Python
from openai import OpenAI

client = OpenAI(
    base_url="https://tokensmind.ai/v1",
    api_key="Tokensmind_API_KEY"
)

completion = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello"}]
)

print(completion.choices[0].message)
{
  "choices": [
    {
      "message": {
        "role": "<string>",
        "content": "<string>"
      },
      "finish_reason": "<string>"
    }
  ],
  "usage": {
    "prompt_tokens": 123,
    "completion_tokens": 123,
    "total_tokens": 123
  }
}
API 沙盒环境支持实时请求调试,直观查看接口返回数据。
为了代码安全,建议:
  • 通过环境变量管理敏感信息(如 API Key),比如对于 Python 调用,使用 os.getenv("TOKENSMIND_API_KEY")
  • 不要在日志/输出中打印敏感信息。
  • 不要将密钥提交到代码仓库,可以通过将 .env 添加到 .gitignore 来防止泄漏。

OpenAPI

授权

Authorization
string
header
必填

Send Authorization: Bearer Tokensmind_API_KEY. Create keys at https://tokensmind.ai/token/add

请求体

application/json
model
string
必填

Model id—see the model hub

messages
object[]
必填

Chat turns with role and content

temperature
number
默认值:0.8

Sampling temperature (0–2); higher = more random

max_tokens
integer
默认值:1024

Max tokens to generate; limit depends on the model

top_p
number
默认值:1

Nucleus sampling

frequency_penalty
number
默认值:0

Penalize repeated tokens

presence_penalty
number
默认值:0

Encourage new topics

stream
boolean
默认值:false

Stream partial results

web_search_options
object

Web search options for search-capable models only

响应

Success

choices
object[]
usage
object