OpenAI CompatibleProtocol duy nhất

Tài Liệu Tích Hợp TexAPI

TexAPI hiện cung cấp duy nhất giao thức OpenAI Compatible. Bạn chỉ cần một API key, một Base URL và có thể tích hợp ngay với hầu hết SDK/IDE phổ biến.

Protocol Profile

Base URL chuẩn OpenAI: https://api.texapi.dev/v1

Xác thực bằng Bearer token trong Authorization header.

Endpoint chính: POST /v1/chat/completions

Hỗ trợ stream (`stream: true`) theo chuẩn OpenAI.

Quick Start

Base URL

https://api.texapi.dev/v1

Authorization Header

Bearer sk-tex-...

Model gợi ý

model-id
Checklist trước khi chạy request đầu tiên
  • 1. Tạo API key trong Dashboard.
  • 2. Trỏ SDK vào Base URL ở trên.
  • 3. Gửi request qua /v1/chat/completions.

Core Endpoints

POST/v1/chat/completions

Endpoint chính cho text generation/chat completion, tương thích OpenAI SDK.

GET/v1/models

Lấy danh sách model public để hiển thị trong IDE hoặc dashboard nội bộ.

Lưu ý quan trọng

Tài liệu này chỉ mô tả OpenAI Compatible protocol. Hãy ưu tiên endpoint /v1/chat/completions cho mọi tích hợp mới.

Ví dụ tích hợp

Mẫu request đầy đủ với OpenAI protocol.

Sample Request

curl
curl https://api.texapi.dev/v1/chat/completions \
  -H "Authorization: Bearer sk-tex-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-id",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Viết 1 câu chào ngắn bằng tiếng Việt."}
    ],
    "temperature": 0.2,
    "stream": false
  }'

JSON Request Template

json
{
  "model": "model-id",
  "messages": [
    { "role": "system", "content": "You are a helpful assistant." },
    { "role": "user", "content": "Hello!" }
  ],
  "temperature": 0.7,
  "max_tokens": 1024,
  "stream": false
}

JSON Response Template

json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "created": 1739491200,
  "model": "model-id",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "Hello!" },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 18,
    "completion_tokens": 12,
    "total_tokens": 30
  }
}

Error Response Example

json
{
  "error": {
    "type": "insufficient_quota",
    "message": "Insufficient balance"
  }
}

Available Models

Đang tải danh sách model mới nhất...

Hiện chưa có model public khả dụng.

Tool Integrations

Cursor

Provider: OpenAI. Đặt custom Base URL = https://api.texapi.dev/v1

Roo Code

Dùng OpenAI-compatible provider và TexAPI key.

Continue

provider=openai, apiBase=https://api.texapi.dev/v1

Aider

Đặt OPENAI_API_KEY và OPENAI_API_BASE=https://api.texapi.dev/v1

OpenAI SDK

base_url/baseURL=https://api.texapi.dev/v1

Cline

OpenAI mode + custom endpoint https://api.texapi.dev/v1

Best Practices

  • 1. Không hardcode API key trong frontend.
  • 2. Retry có giới hạn khi gặp lỗi 429/5xx.
  • 3. Log request ID và usage để đối soát chi phí.