cURL
Các ví dụ không cần thư viện phụ thuộc cho mọi endpoint — hữu ích khi gỡ lỗi và kiểm tra CI.
Liệt kê mô hình
curl https://aiprimetech.io/v1/models \
-H "Authorization: Bearer $CLAUDEAPIKEY"
Messages
curl https://aiprimetech.io/v1/messages \
-H "x-api-key: $CLAUDEAPIKEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"max_tokens": 1024,
"system": "Be concise.",
"messages": [{"role": "user", "content": "What is a CDN?"}]
}'
Chat Completions
curl https://aiprimetech.io/v1/chat/completions \
-H "Authorization: Bearer $CLAUDEAPIKEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-6",
"messages": [
{"role": "system", "content": "Be concise."},
{"role": "user", "content": "What is a CDN?"}
]
}'
Truyền dữ liệu theo luồng
curl -N https://aiprimetech.io/v1/messages \
-H "x-api-key: $CLAUDEAPIKEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model":"claude-sonnet-4-6","max_tokens":512,"stream":true,
"messages":[{"role":"user","content":"Count to five"}]}'
-N tắt cơ chế đệm của chính curl. Nếu không có tùy chọn này, toàn bộ luồng sẽ xuất hiện cùng lúc và trông như tính năng truyền luồng bị lỗi.
Kiểm tra tình trạng trong CI
"c">#!/usr/bin/env bash
set -euo pipefail
code=$(curl -s -o /dev/null -w "%{http_code}" https://aiprimetech.io/v1/models \
-H "Authorization: Bearer $CLAUDEAPIKEY")
[ "$code" = "200" ] || { echo "gateway check failed: $code" >&2; exit 1; }
echo "gateway ok"