Trang chủ / LLM API / Hướng dẫn setup
Setup Guides

Thiết lập client theo từng công cụ

Chọn công cụ ở cột bên trái để xem hướng dẫn đầy đủ. Nội dung bên dưới dùng trực tiếp API key hiện tại của bạn và Base URL thật của hệ thống.

Chuẩn bị trước khi cấu hình

  • Nạp tiền và tạo sẵn API key trong API AI Console.
  • Dùng đúng Base URL cho từng client: có nơi cần `/v1`, có nơi không.
  • Chọn model đang active trong bảng giá, tránh model đã tắt route.
  • Nếu client hỗ trợ custom endpoint, luôn dùng HTTPS endpoint của site hiện tại.

Quy tắc Base URL

  • OpenAI-compatible clients: dùng Base URL có `/v1`.
  • Claude Code env `ANTHROPIC_BASE_URL`: dùng root domain, không thêm `/v1`.
Tài liệu API

Endpoint và lệnh gọi

Bấm vào từng endpoint để xem lệnh curl đầy đủ. Không hiển thị tất cả code cùng lúc để tài liệu gọn và dễ dùng.

Văn bản / hội thoại

chat/completionsPOST

Chat tương thích OpenAI; hỗ trợ messages, tools và stream=true tùy chọn.

https://api.xah.io/v1/chat/completions

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/chat/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": false
}'
completionsPOST

Hoàn thành prompt kiểu cũ; chỉ dùng khi capability này được bật.

https://api.xah.io/v1/completions

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/completions \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "prompt": "Hello",
  "max_tokens": 256
}'
responsesPOST

Request theo định dạng Responses; input/output phụ thuộc contract upstream được bật.

https://api.xah.io/v1/responses

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/responses \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "input": "Hello"
}'
messagesPOST

Định dạng Anthropic Messages. Gửi anthropic-version: 2023-06-01 và max_tokens.

https://api.xah.io/v1/messages

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/messages \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'anthropic-version: 2023-06-01' \
  -d '{
  "model": "MODEL",
  "max_tokens": 1024,
  "messages": [{"role": "user", "content": "Hello"}]
}'

Hình ảnh

images/generationsPOST

Tạo ảnh từ văn bản. Chỉ dùng các field được model ảnh đã chọn công bố: prompt, n, size, quality, response_format, v.v.

https://api.xah.io/v1/images/generations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "prompt": "A red fox in snow",
  "n": 1,
  "size": "1024x1024"
}'
images/generations · image-to-imagePOST

Tạo ảnh từ ảnh cũng gọi endpoint images/generations. Dùng đúng field ảnh trong payload template/contract của model; ví dụ này dùng image_url theo contract của model mẫu.

https://api.xah.io/v1/images/generations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/images/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "prompt": "Turn the reference into a watercolor illustration",
  "image_url": "https://example.com/reference.png",
  "n": 1,
  "size": "1024x1024"
}'
images/editsPOST multipart

Chỉnh sửa/tạo ảnh từ ảnh. image là multipart; prompt và mask phụ thuộc contract của model đã chọn.

https://api.xah.io/v1/images/edits

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/images/edits \
  -H 'Authorization: Bearer API_KEY' \
  -F 'model=MODEL' \
  -F 'prompt=Make it brighter' \
  -F '[email protected]'
images/variationsPOST multipart

Tạo các biến thể từ ảnh đầu vào. image là multipart; không gửi JSON/base64 nếu upstream đã chọn không công bố cách đó.

https://api.xah.io/v1/images/variations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/images/variations \
  -H 'Authorization: Bearer API_KEY' \
  -F 'model=MODEL' \
  -F '[email protected]'

Âm thanh

audio/speechPOST

Chuyển văn bản thành giọng nói. Body JSON chuẩn OpenAI: model, input, voice, instructions tuỳ chọn, response_format, speed và stream_format. Voice, format và giới hạn model phải theo provider được chọn.

https://api.xah.io/v1/audio/speech

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/audio/speech \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "input": "Hello from CKEY",
  "voice": "alloy",
  "response_format": "mp3",
  "speed": 1.0
}'
audio/transcriptionsPOST multipart

Chuyển giọng nói thành văn bản. Multipart chuẩn: file, model, language ISO-639-1 tuỳ chọn, prompt và response_format theo model.

https://api.xah.io/v1/audio/transcriptions

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/audio/transcriptions \
  -H 'Authorization: Bearer API_KEY' \
  -F '[email protected]' -F 'model=gpt-4o-transcribe' -F 'language=en' -F 'response_format=json'
audio/translationsPOST multipart

Dịch audio sang tiếng Anh. Multipart chuẩn: file, model=whisper-1, prompt, response_format và temperature. Endpoint này là legacy/deprecated trong tài liệu OpenAI.

https://api.xah.io/v1/audio/translations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/audio/translations \
  -H 'Authorization: Bearer API_KEY' \
  -F '[email protected]' -F 'model=whisper-1' -F 'response_format=json'

Video (tác vụ / bất đồng bộ)

v1/videosPOST + GET

Endpoint video V1 tương thích OpenAI. POST tạo job tại /v1/videos/generations; polling bằng GET /v1/videos/{JOB_ID}. Dùng field seconds theo contract V1.

https://api.xah.io/v1/videos/generations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/videos/generations \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "prompt": "A gentle camera move across a mountain",
  "seconds": 8
}

# Poll: GET https://api.xah.io/v1/videos/JOB_ID'
v2/video_generationPOST + GET + DELETE

Endpoint video Task API V2 của CKEY. POST tạo job; polling bằng GET /v2/query/video_generation/{JOB_ID}; hủy bằng DELETE /v2/video_generation/{JOB_ID}. Dùng field duration theo contract V2; không đổi về route V1.

https://api.xah.io/v2/video_generation

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v2/video_generation \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "content": [{"type": "text", "text": "A gentle camera move across a mountain"}],
  "duration": 6,
  "ratio": "16:9"
}

# Poll: GET https://api.xah.io/v2/query/video_generation/JOB_ID
# Cancel: DELETE https://api.xah.io/v2/video_generation/JOB_ID'

Embedding / xếp hạng / an toàn / tìm kiếm

embeddingsPOST

Chuyển một chuỗi hoặc mảng chuỗi thành vector.

https://api.xah.io/v1/embeddings

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/embeddings \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "input": ["first text", "second text"]
}'
rerankPOST

Xếp hạng tài liệu theo truy vấn. Bắt buộc có query và documents; top_n không được lớn hơn số lượng tài liệu.

https://api.xah.io/v1/rerank

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/rerank \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "query": "latest AI news",
  "documents": ["doc A", "doc B"],
  "top_n": 2
}'
moderationsPOST

Phân loại input bằng model moderation được bật.

https://api.xah.io/v1/moderations

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/moderations \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "input": "Text to classify"
}'
searchPOST

Contract tìm kiếm phụ thuộc nhà cung cấp/model. Chỉ gửi field tùy chọn khi tài liệu của model đã chọn cho phép.

https://api.xah.io/v1/search

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1/search \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "query": "latest AI news",
  "max_results": 5
}'

Endpoint native của nhà cung cấp

geminiPOST

Định dạng native Google Gemini. Streaming dùng :streamGenerateContent?alt=sse, không dùng field stream tự suy diễn trong body.

https://api.xah.io/v1beta/models/MODEL:generateContent

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/v1beta/models/MODEL:generateContent \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "contents": [{"role": "user", "parts": [{"text": "Hello"}]}]
}'
ollamaPOST

Định dạng chat native của Ollama.

https://api.xah.io/api/chat

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/api/chat \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "messages": [{"role": "user", "content": "Hello"}],
  "stream": false
}'
api/generatePOST

Định dạng tạo prompt native của Ollama.

https://api.xah.io/api/generate

Lệnh đầy đủ
API_KEY="YOUR_CKEY_API_KEY"

curl https://api.xah.io/api/generate \
  -H "Authorization: Bearer $API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "model": "MODEL",
  "prompt": "Hello",
  "stream": false
}'
Quy tắc contract

Tạo ảnh từ text và tạo ảnh từ ảnh đều gọi POST /images/generations. Field ảnh không được tự đổi tên: dùng đúng payload template/contract của model đang chọn. Không dùng images/edits hoặc images/variations thay thế cho model chỉ công bố images/generations.

OpenAI-compatible chat/completions /v1

Cursor

Cursor nên đi qua chế độ OpenAI-compatible với custom API key và custom base URL.

Thông tin cần điền

Provider
OpenAI-compatible
API Key
sk-YOUR_API_KEY
Base URL
https://api.xah.io/v1
Model
gpt-5.5
Route
chat/completions
Yêu cầu gói
Cần gói Cursor hỗ trợ custom API endpoint.

Các bước đề xuất

  1. 1Mở Cursor Settings rồi vào khu vực AI / Models / API Keys.
  2. 2Bật custom OpenAI key hoặc custom provider nếu bản Cursor của bạn dùng tên khác.
  3. 3Dán API key và Base URL bên dưới.
  4. 4Chọn model gợi ý hoặc model khác đang active trong bảng giá.

Khối cấu hình mẫu

Provider: OpenAI-compatible
API Key: sk-YOUR_API_KEY
Base URL: https://api.xah.io/v1
Model: gpt-5.5
Route: chat/completions

Model nên thử

  • gpt-5.5
  • claude-opus-4.6
  • claude-opus-4.7
  • claude-opus-4.8
  • claude-sonnet-4.6
  • deepseek-v4.1-flash

Lưu ý

  • Cursor dùng kiểu OpenAI-compatible nên Base URL phải có `/v1`.
  • Nếu một model không chạy trong Cursor, hãy thử model OpenAI-compatible khác trong danh sách active.
  • Sau khi lưu, test bằng một prompt ngắn để xác nhận route `chat/completions` hoạt động.
Liên hệ hỗ trợ
Chúng tôi luôn sẵn sàng hỗ trợ bạn