GateAI · API docs & playground

Model name dùng trong API

Trường model nhận Gateway ID hoặc Upstream ID trong bảng. Chỉ model đang bật mới được gọi. Danh sách tự cập nhật theo cấu hình đang triển khai; xem docs không cần key.

Gateway ID / model nameUpstream IDEndpointOutput
image-flux-free@cf/black-forest-labs/flux-2-klein-4b/v1/imageText · SSE
image-fluxblack-forest-labs/flux.2-klein-4b/v1/imageText · SSE
image-flux-problack-forest-labs/flux.2-pro/v1/imageText · SSE
image-nano-bananagoogle/gemini-nano-banana-2.1/v1/imageText · SSE
image-gpt-miniopenai/gpt-image-1-mini/v1/imageText · SSE
image-seedreambytedance-seed/seedream-5-0-lite/v1/imageText · SSE
image-grokx-ai/grok-imagine-image-2.0/v1/imageText · SSE
chat-freenvidia/nemotron-3-ultra-550b-a55b:free/v1/chat/completionsText · SSE
chat-apodex-freeapodex/apodex-1.1-mini:free/v1/chat/completionsText · SSE
chat-laguna-freepoolside/laguna-xs-2.1:free/v1/chat/completionsText · SSE
chat-nano-freenvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free/v1/chat/completionsText · SSE
chat-liquid-freeliquid/lfm-2.5-2.6b:free/v1/chat/completionsText · SSE
embed-nemotron-freenvidia/nemotron-3-embed-1b:free/v1/embeddings2048 chiều
embed-nemotron-vl-freenvidia/llama-nemotron-embed-vl-1b-v2:free/v1/embeddings2048 chiều
embed-liquid-freeliquid/lfm-2.5-embedding-350m:free/v1/embeddings1024 chiều

Các model hiện tại là free, không tự fallback sang model trả phí. Free có quota và không có bảo đảm uptime. Laguna free dự kiến ngừng 31/10/2026.

Tài liệu API

Base URL: https://ai-gateway.schoolsai.work/v1. Dev nhận project key gai_… từ quản trị viên. Gọi API từ backend của ứng dụng; không nhúng key vào frontend công khai.

Headers & idempotency

Authorization: Bearer <PROJECT_API_KEY>
Content-Type: application/json
Idempotency-Key: <unique-request-id>

Idempotency-Key tùy chọn cho chat/responses/embedding; nếu gửi phải dài 8–150 ký tự. Nên gửi để retry an toàn. Nếu bỏ qua, mỗi lần gọi là một job mới. Giữ nguyên key và body khi retry cùng yêu cầu; tạo key mới cho yêu cầu mới. Yêu cầu đã hoàn tất trả lại kết quả cũ; đang xử lý trả 409. Rate limit áp dụng theo project, kể cả model free.

Endpoints

MethodPathSử dụng
GET/v1/modelsDanh sách model đang bật; cần project key.
POST/v1/chat/completionsChat, function tools, structured output, multimodal theo model; stream tùy chọn.
POST/v1/responsesResponses stateless: input, instructions, function tools, text.format, stream.
POST/v1/imageTạo ảnh bất đồng bộ (202 + job); poll GET /v1/jobs/{id}, ảnh tự xóa sau 3 ngày. Model và giá: trường kind: image, price_usd trong /v1/models; chi tiết ở docs/api.md.
POST/v1/embeddingsVector float cho text hoặc batch text.
GET/v1/balanceCredit và giới hạn của project.
GET/v1/jobs/{id}Trạng thái yêu cầu thuộc project.

Chat & streaming

Nhận role system/developer/user/assistant/tool; content dạng text hoặc content parts (text, image_url, input_audio, video_url). Hỗ trợ tools, tool_choice, parallel_tool_calls, response_format, temperature, top_p, stop, seed, reasoning và giới hạn token. Khả năng thực tế tùy model/provider; gateway yêu cầu provider hỗ trợ tham số đã gửi. Payload tối đa 4 MiB sau khi serialize JSON; mặc định output 4096 token, cho phép max_tokens hoặc max_completion_tokens đến 32768, vẫn chịu giới hạn model.

curl -N https://ai-gateway.schoolsai.work/v1/chat/completions \
  -H "Authorization: Bearer $GATEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"model":"chat-apodex-free","stream":true,"messages":[{"role":"user","content":"Xin chào"}]}'

stream:false trả JSON với choices[].message.content. stream:true trả SSE: đọc từng data:, ghép choices[].delta.content, kết thúc bằng [DONE]. Ngắt kết nối không đồng nghĩa provider đã hủy; kiểm tra job trước khi gửi yêu cầu mới.

OpenAI SDK · tool calling nhiều lượt

Kiểm thử production ngày 05/10/2026: chat-liquid-free đã qua tool calling hai lượt, streaming tool calls và JSON Schema. chat-apodex-free đã qua Responses JSON/SSE nhưng provider từ chối tool_choice=required (404) và request JSON Schema đã thử (400). Khả năng có thể thay đổi theo endpoint; dùng chat-liquid-free cho ví dụ tool bên dưới.

import os, json
from openai import OpenAI
client = OpenAI(api_key=os.environ["GATEAI_API_KEY"],
                base_url="https://ai-gateway.schoolsai.work/v1")
messages = [{"role":"user", "content":"Tính 2 + 3 bằng tool add"}]
tools = [{"type":"function", "function":{
  "name":"add", "description":"Add two numbers",
  "parameters":{"type":"object", "properties":{
    "a":{"type":"number"}, "b":{"type":"number"}},
    "required":["a","b"], "additionalProperties":False}}}]
r = client.chat.completions.create(model="chat-liquid-free",
    messages=messages, tools=tools, tool_choice="required")
m = r.choices[0].message
messages.append(m.model_dump(exclude_none=True))
for call in m.tool_calls or []:
    if call.function.name != "add":
        raise ValueError("Unknown tool")
    args = json.loads(call.function.arguments)
    messages.append({"role":"tool", "tool_call_id":call.id,
                     "content":json.dumps(args["a"] + args["b"])})
r = client.chat.completions.create(model="chat-liquid-free",
    messages=messages, tools=tools)
print(r.choices[0].message.content)

Ứng dụng thực thi function và gửi kết quả về model. Streaming giữ nguyên delta.tool_calls; ghép arguments theo index trước khi parse JSON. Giữ lại reasoning_details trong lịch sử khi model trả trường này. Không chạy tên hàm/lệnh tùy ý từ model; chỉ thực thi tool đã đăng ký.

Structured output & Responses API

# Chat: thêm response_format theo JSON Schema
response_format = {"type":"json_schema", "json_schema":{
  "name":"answer", "strict":True, "schema":{"type":"object",
  "properties":{"answer":{"type":"string"}},
  "required":["answer"], "additionalProperties":False}}}

# Responses: cùng alias hoặc ID gốc; stream cũng được hỗ trợ
r = client.responses.create(model="chat-apodex-free",
    input="Say hello", max_output_tokens=256)
print(r.output_text)
for event in client.responses.create(model="chat-apodex-free",
    input="Say hello", stream=True):
    if event.type == "response.output_text.delta":
        print(event.delta, end="")

Responses dùng tools dạng function với name/parameters ở cấp ngoài; vòng tiếp theo gửi input items gồm function_call và function_call_output. Structured output dùng text.format. Stream giữ event type như response.output_text.delta, response.completed, response.incomplete; không dùng [DONE] như Chat. Chưa hỗ trợ lưu response, previous_response_id, background hoặc truy xuất response theo ID.

Computer use & giới hạn tương thích

Có thể khai báo function click/type/screenshot rồi chạy chúng trong browser/desktop sandbox của ứng dụng và gửi kết quả/ảnh về model hỗ trợ vision. Kiểm thử ảnh ngày 06/10/2026: chat-nano-free trả được tọa độ chuẩn hóa, nhưng bài nhiều bước chưa đạt do NVIDIA báo quá tải (16/16 requests). Client cần kiểm tra và chuyển đổi tọa độ rõ ràng. Gateway không cung cấp trình duyệt/máy ảo và chưa hỗ trợ tool computer_use riêng của vendor. Không đồng nghĩa tất cả model free hỗ trợ vision/tools/schema.

Chưa bật web search, file parsing, built-in server tools, plugin trả phí, model fallback tùy ý, Realtime, Files, Batch, fine-tuning hoặc media/Runpod. Không nhận models/provider/plugins từ client để tránh vượt chính sách chi phí. Chỉ n=1; stream giới hạn 180 giây, 2 triệu ký tự và 256 KiB mỗi event. Quota free và giới hạn provider vẫn áp dụng.

Embeddings

input là chuỗi không rỗng hoặc mảng 1–16 chuỗi không rỗng. Output tại data[].embedding, thứ tự tại data[].index. Nhận encoding_format float hoặc base64 (tương thích SDK). dimensions nếu gửi phải đúng số chiều trong bảng. Chưa nhận ảnh hoặc token IDs.

curl https://ai-gateway.schoolsai.work/v1/embeddings \
  -H "Authorization: Bearer $GATEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"model":"embed-liquid-free","input":["Bút chì đỏ","Bút chì xanh"]}'

Liquid: 1024 chiều, tối đa 1500 bytes JSON và context provider 512 token. NVIDIA: 2048 chiều, tối đa 12000 bytes JSON. Bytes không tương đương token; provider có thể từ chối input dài. Dùng cùng model cho index và query, không trộn vector giữa các model dù cùng số chiều.

Lỗi thường gặp

401: key sai/đã thu hồi. 400/422: model, tham số hoặc header không hợp lệ. 402: thiếu credit. 409: idempotency trùng hoặc job đang xử lý. 413: input quá dài. 429: rate limit hoặc budget. 502: kết quả provider chưa xác định; xem job_id nếu có. 503: dịch vụ/provider chưa sẵn sàng. Chi tiết nằm trong trường detail hoặc error; lỗi SSE có thể nằm trong sự kiện stream.

OpenAPI tương tác · OpenAPI JSON

Gọi thử API

Chọn model ID, gọi thử chat hoặc tạo embedding bằng project API key.

Chỉ dùng dữ liệu mẫu với endpoint free. Không gửi thông tin bí mật hoặc dữ liệu cá nhân. Provider có thể ghi log; free có quota và có thể tạm ngừng.

Key chỉ giữ trong bộ nhớ trang, không lưu vào trình duyệt. Mỗi lần test tạo Idempotency-Key mới. Embedding hiển thị kích thước và 8 giá trị đầu.

Kết quả sẽ hiển thị ở đây.

Ví dụ curl

Tải danh sách để chọn model.

Danh sách đã xác thực

Gateway IDUpstream IDLoại