Skip to content

시작하기

API 키를 생성하고 첫 호출을 실행하세요

Fast-Token API 직접 호출

TIP

<Fast-Token_API_KEY>Fast-Token Key로 바꾸세요. key의 유효 기간과 사용 한도를 확인하세요.

사용 가능한 model 목록은 모델 광장에서 확인하고, 모델 이름을 복사해 교체하면 됩니다.

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?"
      }
    ]
  }'

스트리밍 호출은 stream: true 파라미터만 추가하면 됩니다.

OpenAI SDK 사용

<Fast-Token_API_KEY>Fast-Token Key로 바꾸세요. key의 유효 기간과 사용 한도를 확인하세요. 사용 가능한 model 목록은 모델 광장에서 확인하고, 모델 이름을 복사해 교체하면 됩니다.

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();

검색을 지원하는 모델에는 아래 파라미터를 추가할 수 있습니다.

python
web_search_options={},  # 搜索参数

사용 가능한 모델: gpt-4o-search-preview, gpt-4o-mini-search-preview.

INFO

검색 모델은 아직 temperature 등 세부 파라미터를 지원하지 않습니다.