Skip to content

Bắt đầu

Tạo khóa API và thực hiện lần gọi đầu tiên

Gọi trực tiếp Fast-Token API

TIP

Thay <Fast-Token_API_KEY> bằng Fast-Token Key của bạn. Lưu ý thời hạn hiệu lực và hạn mức của key.

Danh sách model khả dụng xem tại Kho mô hình; sao chép tên mô hình để thay thế.

py
import requests
import json

response = requests.post(
    url="https://dev-api.ai-study.icu/v1/chat/completions",
    headers={
        "Authorization": "Bearer <Fast-Token_API_KEY>",
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "model": "gpt-4o-mini",  # 替换模型 id
        "messages": [
            {
                "role": "user",
                "content": "What is the meaning of life?"
            }
        ]
    })
)
ts
// 请在 https://dev-api.ai-study.icu 域名下尝试,否则有浏览器跨域问题
fetch("https://dev-api.ai-study.icu/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer <Fast-Token_API_KEY>",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "gpt-4o-mini",
    messages: [
      {
        role: "user",
        content: "What is the meaning of life?",
      },
    ],
  }),
});
sh
curl 'https://dev-api.ai-study.icu/v1/chat/completions' \
  -H 'Authorization: Bearer <Fast-Token_API_KEY>' \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": "What is the meaning of life?"
      }
    ]
  }'

Hỗ trợ gọi streaming — chỉ cần thêm tham số stream: true.

Dùng OpenAI SDK

Thay <Fast-Token_API_KEY> bằng Fast-Token Key của bạn. Lưu ý thời hạn hiệu lực và hạn mức của key. Danh sách model khả dụng xem tại Kho mô hình; sao chép tên mô hình để thay thế.

py
from openai import OpenAI
import random

client = OpenAI(
    base_url="https://dev-api.ai-study.icu/v1",
    api_key="<Fast-Token_API_KEY>",
)

completion = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "developer",
            "content": "Always answer in English"
        },
        {
            "role": "user",
            "content": "What is the meaning of life?"
        }
    ],
    temperature=0.8,
    max_tokens=1024,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0,
    seed=random.randint(1, 1000000000),
)

print(completion.choices[0].message.content)
js
import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://dev-api.ai-study.icu/v1",
  apiKey: "<Fast-Token_API_KEY>",
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: "gpt-4o-mini",
    messages: [
      {
        role: "user",
        content: "What is the meaning of life?",
      },
    ],
  });

  console.log(completion.choices[0].message);
}

main();

Với mô hình hỗ trợ tìm kiếm, bạn có thể thêm tham số sau:

python
web_search_options={},  # 搜索参数

Mô hình khả dụng: gpt-4o-search-preview, gpt-4o-mini-search-preview.

INFO

Mô hình tìm kiếm hiện chưa hỗ trợ các tham số chi tiết như temperature.