先分清 SDK、Codex 和 Claude Code 的地址与认证规则,再用一个独立的 Chat Completions 小请求检查文本输出。模型与费用按当前授权服务确认,不批量试错。
内容更新 2026-07-26Base URL 要同时匹配服务方和客户端的路径拼接规则;先检查配置,再经人工确认发一次 hi,分别核对返回结果与费用元信息。
# 1a1_check.py — Python 3.10+;默认仅打印检查模式,不读取 Key 或联网。
import argparse
import getpass
import http.client
import json
import warnings
from urllib.error import HTTPError, URLError
from urllib.request import HTTPRedirectHandler, Request, build_opener
URL = "https://1a1api.top/v1/chat/completions"
MAX_BYTES = 65536
class NoRedirect(HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
raise HTTPError(req.full_url, code, "redirect_blocked", headers, fp)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--send", action="store_true")
parser.add_argument("--model", default="YOUR_MODEL_ID")
args = parser.parse_args()
if not args.send:
print("CHECK_ONLY: no credential read; no request sent")
return 0
model = args.model.strip()
if not model or model == "YOUR_MODEL_ID" or any(c.isspace() for c in model):
print("STOP: choose an authorized Chat Completions model first")
return 2
print("Target:", URL)
print("One paid request; input is fictional hi; no automatic retry.")
if input("Type SEND-ONCE to continue: ").strip() != "SEND-ONCE":
print("CANCELLED")
return 2
try:
with warnings.catch_warnings():
warnings.simplefilter("error", getpass.GetPassWarning)
key = getpass.getpass("Key (local trusted terminal only): ")
except getpass.GetPassWarning:
print("STOP: hidden terminal input unavailable")
return 2
if not key or any(c.isspace() for c in key) or "\x00" in key:
print("STOP: invalid credential input; value not displayed")
return 2
payload = {"model": model, "messages": [{"role": "user", "content": "hi"}],
"stream": False}
try:
request = Request(URL, data=json.dumps(payload).encode("utf-8"),
headers={"Authorization": "Bearer " + key,
"Content-Type": "application/json"},
method="POST")
with build_opener(NoRedirect()).open(request, timeout=45) as response:
status = response.status
raw = response.read(MAX_BYTES + 1)
if len(raw) > MAX_BYTES:
print("STOP: response size exceeds local check limit")
return 1
result = json.loads(raw)
choices = result.get("choices") if isinstance(result, dict) else None
first = choices[0] if isinstance(choices, list) and choices else None
message = first.get("message") if isinstance(first, dict) else None
text = message.get("content") if isinstance(message, dict) else None
has_text = isinstance(text, str) and bool(text.strip())
normal_stop = isinstance(first, dict) and first.get("finish_reason") == "stop"
ok = status == 200 and has_text and normal_stop and "error" not in result
print(json.dumps({"httpStatus": status, "textPresent": has_text,
"normalStop": normal_stop, "passed": ok}))
return 0 if ok else 1
except HTTPError as error:
print(json.dumps({"httpStatus": error.code, "passed": False}))
error.close()
except (URLError, TimeoutError, OSError):
print("FAILED: network, TLS or timeout; no raw details printed")
except http.client.HTTPException:
print("FAILED: HTTP protocol or incomplete response; no raw details printed")
except (ValueError, TypeError, UnicodeError):
print("FAILED: request or response format; no raw details printed")
return 1
if __name__ == "__main__":
try:
raise SystemExit(main())
except (EOFError, KeyboardInterrupt):
print("CANCELLED")
raise SystemExit(2)
以下是 1A1API 帮助页的工具约定,不是所有兼容 API 的通用地址。版本或路径不一致时,先核对最终 endpoint;不要把完整接口路径填进 Base URL 字段。
| 客户端与用途 | 服务帮助页的 Base URL | 认证与使用边界 |
|---|---|---|
| OpenAI SDK:Chat Completions 或 Responses | https://1a1api.top/v1 | 使用该服务签发的 Key;SDK 分别拼 chat/completions 或 responses。Responses 并不自动意味着根地址。 |
| Codex CLI:Responses | https://1a1api.top | 这是服务方 Codex 页面约定。需与所装 CLI 版本、最终请求路径及认证方式一起确认,不外推桌面 App 或其他 Responses 客户端。 |
| Claude Code CLI:Messages | https://api.1a1api.top | 服务页使用 ANTHROPIC_BASE_URL 与 ANTHROPIC_AUTH_TOKEN。必须配套服务凭据,不仅改域名而保留官方登录的有效凭据。 |
| Cursor、Cherry Studio、Anthropic SDK 或其他工具 | 按具体客户端/版本文档 | 不能从工具名称猜路径或复制另一工具的认证变量;先确认自定义入口和所需能力受支持。 |
下面两种平台命令只选适合自己的一条。先替换模型占位符;代码默认不会联网,--send 仍要求本人再次确认。输入是虚构 hi,不要求模型回复某个固定词。
{
"httpStatus": 200,
"textPresent": true,
"normalStop": true,
"passed": true
}
用于人工或 AI 协助判断,不提供原始配置或返回体;请求 ID 只在授权支持渠道按需提供。
工具与版本:<名称、版本、操作系统>
服务签发方与认证类型:<名称、API Key 或订阅;不写凭据>
公开 Base URL:<无查询参数、无秘密>
协议及目标路径类别:<Chat Completions / Responses / Messages>
模型权限:<本人已确认 / 未确认,不附控制台截图>
检查结果:<CHECK_ONLY 或脚本四项摘要>
请求时间与时区:<时间>
费用元信息是否核对:<是 / 尚未,不附客户信息>
请只检查入口、协议、版本和凭据来源是否匹配。
有证据缺口就指出所需公开文档,不索取 Key、Token、Cookie、完整配置或日志。