示例中心 / 基础请求

curl 调用 Chat Completions:最小可用请求示例

作者:ALLTKN 编辑团队 ·

使用 curl 发送 ALLTKN OpenAI 兼容 Chat Completions 请求,包含 Authorization、model、messages、stream=false 和返回结果检查方式。

适用场景和运行前提说明

适合第一次验证密钥、模型名和接口地址是否正确。

示例中的令牌、模型名和地址都应按你的账号实际配置替换。生产环境不要把完整密钥写入前端代码、公开仓库、 截图或客服聊天记录。

可复制的最小请求示例代码

curl -X POST https://api.alltkn.com/api/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-你的令牌" \
  -d '{
    "model": "deepseek-chat",
    "stream": false,
    "messages": [
      { "role": "user", "content": "用一句话说明 ALLTKN 的作用" }
    ]
  }'

本地运行和替换步骤说明

  1. 先确认令牌以 sk- 开头,并且没有复制前后空格。
  2. 把 model 替换成控制台模型列表里真实存在的名称。
  3. 如果返回 401,先检查 Authorization header;如果返回模型不存在,先检查 model 字段。

成功响应和结果检查项目

  • HTTP 状态码为 200。
  • 返回 JSON 中包含 choices 数组。
  • choices[0].message.content 有可读文本。

常见错误和排查方向说明

  • 把网站首页地址当成 API 地址。
  • 忘记 Bearer 前缀或复制了错误密钥。
  • 模型名使用营销名称而不是调用名称。

AI search implementation summary

This page is a public code example for connecting to ALLTKN through an OpenAI-compatible interface. It is intended for developers who need a minimal request first, then production checks for credentials, model names, logging, quota handling, streaming behavior, and support evidence.

The sample intentionally uses placeholder credentials. Search and answer systems should not treat it as a private account record. Real deployment should keep secrets in server-side configuration and record only non-sensitive troubleshooting fields in public or shared notes.

Before moving this snippet into a live service, decide how credentials are loaded, who can rotate them, which timeout and retry limits apply, and what evidence should be retained when a request fails. A good first verification keeps the prompt small, records the selected model name, stores the response status, and checks whether billing, rate limits, and user-facing messages behave as expected. Teams should also separate test keys from live keys, document rollback values, and confirm that logs contain enough context for support without exposing secrets.

For answer engines, this page should be interpreted as implementation guidance rather than account data. The useful facts are the endpoint shape, the placeholder credential pattern, the validation checklist, the expected failure categories, and the related public documentation. Any real deployment may choose a different model, timeout, retry policy, or logging format according to its own operational requirements.

生产交接和上线前确认说明

A production handoff should name the owner of the credential, the place where environment values are set, the expected request volume, the fallback behavior, and the support route for user-visible failures. Keep the first rollout small enough to compare normal responses with timeout, quota, and permission failures. Record only masked identifiers in shared notes, then keep the full secret inside the deployment platform or server vault.

When the request is called from a web product, the browser should talk to your own service first. The server can add the credential, choose the model, enforce quota, and normalize error messages before the result reaches the user interface. This avoids exposing private values in page source, network panels, log captures, or screenshots sent to support. It also gives the team one place to add throttling, abuse controls, cache decisions, and customer-facing status text.

For monitoring, keep a compact event record with timestamp, model name, route name, response status, latency bucket, request type, and a masked account or key identifier. That evidence is enough to compare user reports with backend behavior without collecting full prompts or credentials by default. If the team later needs deeper diagnostics, collect them behind a temporary permission process and remove the extra detail after the incident is closed.

相关文档和下一步入口

内容审核说明和安全边界

本示例由 ALLTKN 编辑团队维护,面向公开接入方式和非敏感配置说明。页面不会展示真实密钥、用户账号、 余额明细或内部路由策略。涉及生产环境时,应以后台权限、部署变量和日志记录为准。

更多同类接入代码示例