KONG API AI Tài liệu Bắt đầu miễn phí

Bắt đầu

Bắt đầu nhanh

Ba bước để gọi AI qua KONG API AI: tạo tài khoản, tạo khoá, gửi yêu cầu đầu tiên bằng cURL, Python hoặc Node.js.

1. Tạo tài khoản

Mở trang đăng ký, nhập email và mật khẩu. Mọi tài khoản bắt đầu ở gói Free, không cần thẻ.

2. Tạo khoá

Trong console, vào API Keys và tạo một khoá. Khoá bắt đầu bằng gw_live_ hoặc gw_test_.

3. Gửi yêu cầu đầu tiên

Địa chỉ gốc của API là:

text
https://kongapiai.com/v1

Thay gw_live_… bằng khoá của bạn và MODEL_ID bằng một model trong trang Model và giá.

cURL
curl https://kongapiai.com/v1/chat/completions \
  -H "Authorization: Bearer gw_live_…" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"model": "MODEL_ID", "messages": [{"role": "user", "content": "Xin chào"}]}'
Python
# pip install openai
from openai import OpenAI
import uuid

client = OpenAI(base_url="https://kongapiai.com/v1", api_key="gw_live_…")
r = client.chat.completions.create(
    model="MODEL_ID",
    messages=[{"role": "user", "content": "Xin chào"}],
    extra_headers={"Idempotency-Key": str(uuid.uuid4())},
)
print(r.choices[0].message.content)
Node.js
// npm install openai
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://kongapiai.com/v1", apiKey: "gw_live_…" });
const r = await client.chat.completions.create(
  { model: "MODEL_ID", messages: [{ role: "user", content: "Xin chào" }] },
  { headers: { "Idempotency-Key": crypto.randomUUID() } },
);
console.log(r.choices[0].message.content);

Vì sao nên gửi Idempotency-Key

Idempotency-Key là một mã bạn tự sinh cho mỗi yêu cầu. Nếu mạng rớt và mã của bạn gửi lại cùng yêu cầu với cùng mã đó, KONG API AI không gọi nhà cung cấp lần hai và không tính tiền hai lần. Chi tiết ở trang API.

Bước tiếp theo