> For the complete documentation index, see [llms.txt](https://docs.tinyapi.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tinyapi.org/tinytoken-docs.md).

# TinyToken Docs

TinyToken Docs สำหรับลูกค้าและนักพัฒนา ใช้เป็นคู่มือเริ่มต้น เติมเครดิต สร้าง API Key เรียกใช้โมเดล และตั้งค่าเครื่องมือ AI ผ่าน TinyAPI

### Quick Start

#### 1. สมัครบัญชี

ลิงก์สมัคร: <https://tinyapi.org/sign-up>

ใช้หน้านี้เฉพาะขั้นตอนสมัครบัญชี TinyToken เท่านั้น ไม่ปะปนกับการเข้าสู่ระบบ

วิธีแนะนำ: สมัครด้วย Google เพื่อให้สร้างบัญชีเร็วที่สุด

วิธีใช้ชื่อผู้ใช้:

1. เปิดหน้า Sign up
2. กรอกชื่อผู้ใช้
3. ตั้งรหัสผ่าน 8-20 ตัวอักษร
4. ยืนยันรหัสผ่าน
5. กดสร้างบัญชี

![สมัครบัญชี](https://tinyapi.org/docs-register.png)

#### 2. เข้าสู่ระบบ

ลิงก์เข้าสู่ระบบ: <https://tinyapi.org/sign-in>

ใช้ Google หรือชื่อผู้ใช้และรหัสผ่านที่สมัครไว้ หากเข้าสู่ระบบไม่ได้ ให้ตรวจสอบว่ากรอกบัญชีถูกต้อง และลองรีเฟรชหน้าอีกครั้ง

![เข้าสู่ระบบ](https://tinyapi.org/docs-sign-in.png)

#### 3. เติมเครดิต

ลิงก์กระเป๋าเงิน: <https://tinyapi.org/wallet>

ขั้นตอนเติมเครดิต:

1. เปิดหน้า Wallet
2. เลือกจำนวนเงินหรือกรอกจำนวนเอง
3. สแกน QR ด้วยแอปธนาคารของคุณ แล้วอัปโหลดสลิปด้านล่าง
4. ส่งคำขอเติมเงิน
5. รอ admin ตรวจสอบและอนุมัติ

เมื่อระบบอนุมัติแล้ว เครดิตจะเพิ่มเข้าในบัญชีโดยอัตโนมัติ

#### 4. สร้าง API Key

ลิงก์ API Keys: <https://tinyapi.org/keys>

1. เปิดหน้า API Keys
2. กดสร้าง API Key
3. ตั้งชื่อคีย์เพื่อจำง่าย
4. คัดลอกคีย์ไว้ทันที
5. นำไปใช้ใน header แบบนี้

```http
Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Content-Type: application/json
```

> ห้ามส่ง API Key แบบเต็มให้คนอื่น หากต้องแจ้งปัญหา ให้แสดงเฉพาะต้นและท้าย เช่น `sk-abcd...wxyz`

#### 5. ตรวจสอบก่อนใช้งาน

ก่อนเรียก API ให้ตรวจสอบ 5 อย่างนี้:

* บัญชีเข้าสู่ระบบแล้ว
* เครดิตคงเหลือเพียงพอ
* API Key ยังใช้งานได้
* ใช้ Base URL ถูกต้อง
* ชื่อโมเดลตรงกับหน้าราคาโมเดล

Base URL หลัก:

```
https://api.tinyapi.org/v1
```

#### 6. โมเดลเข้ากันได้

TinyAPI รองรับรูปแบบ API หลักหลายแบบ:

| ประเภท                  | Endpoint               | เหมาะกับ                    |
| ----------------------- | ---------------------- | --------------------------- |
| OpenAI Chat Completions | /v1/chat/completions   | GPT-compatible apps         |
| OpenAI Responses API    | /v1/responses          | SDK/แอปที่ใช้ Responses API |
| Anthropic Messages API  | /v1/messages           | Claude-compatible apps      |
| Image Generation        | /v1/images/generations | สร้างภาพ                    |
| Models List             | /v1/models             | ดูโมเดลที่ใช้งานได้         |

ถ้าแอปถาม OpenAI Base URL ให้ใส่:

```
https://api.tinyapi.org/v1
```

ถ้าแอปถาม Anthropic Base URL ให้ใช้โดเมนเดียวกัน และเรียก path `/v1/messages`

### API Reference

#### ดูเครดิตคงเหลือของ API Key

```bash
curl https://api.tinyapi.org/api/usage/token \
  -H "Authorization: Bearer sk-YOUR_API_KEY"
```

ตัวอย่างผลลัพธ์:

```json
{
  "code": true,
  "message": "ok",
  "data": {
    "object": "token_usage",
    "name": "my-api-key",
    "total_granted": 1000000,
    "total_used": 250000,
    "total_available": 750000,
    "unlimited_quota": false,
    "expires_at": 0
  }
}
```

#### ดูรายการโมเดล

```bash
curl https://api.tinyapi.org/v1/models \
  -H "Authorization: Bearer sk-YOUR_API_KEY"
```

ตัวอย่างผลลัพธ์:

```json
{
  "success": true,
  "object": "list",
  "data": [
    {
      "id": "your-model-id",
      "object": "model",
      "owned_by": "custom",
      "supported_endpoint_types": ["openai", "anthropic"]
    }
  ]
}
```

#### OpenAI-compatible Chat

Endpoint:

```
POST https://api.tinyapi.org/v1/chat/completions
```

ตัวอย่าง non-streaming:

```bash
curl https://api.tinyapi.org/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {"role": "user", "content": "สวัสดี แนะนำตัวสั้น ๆ"}
    ]
  }'
```

ตัวอย่าง streaming:

```bash
curl https://api.tinyapi.org/v1/chat/completions \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "stream": true,
    "messages": [
      {"role": "user", "content": "เขียนคำทักทายสั้น ๆ"}
    ]
  }'
```

#### Anthropic-compatible Chat

Endpoint:

```
POST https://api.tinyapi.org/v1/messages
```

Header สำคัญ:

```http
Authorization: Bearer sk-YOUR_API_KEY
anthropic-version: 2023-06-01
content-type: application/json
```

ตัวอย่าง:

```bash
curl https://api.tinyapi.org/v1/messages \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "your-claude-model-id",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello. Please introduce yourself briefly."}
    ]
  }'
```

#### OpenAI Responses API

Endpoint:

```
POST https://api.tinyapi.org/v1/responses
```

ตัวอย่าง:

```bash
curl https://api.tinyapi.org/v1/responses \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "input": "สรุปข้อดีของ TinyAPI เป็น bullet สั้น ๆ"
  }'
```

#### Image Generation

Endpoint:

```
POST https://api.tinyapi.org/v1/images/generations
```

ตัวอย่าง:

```bash
curl https://api.tinyapi.org/v1/images/generations \
  -H "Authorization: Bearer sk-YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-image-model-id",
    "prompt": "A clean futuristic API dashboard, Thai fintech style",
    "size": "1024x1024"
  }'
```

### Error Response และ Rate Limit

รูปแบบ error แบบ OpenAI-compatible:

```json
{
  "error": {
    "message": "รายละเอียดข้อผิดพลาด",
    "type": "new_api_error",
    "param": "",
    "code": "invalid_request"
  }
}
```

รูปแบบ error แบบ Claude Messages API:

```json
{
  "type": "error",
  "error": {
    "type": "invalid_request",
    "message": "รายละเอียดข้อผิดพลาด"
  }
}
```

| Status | สาเหตุที่พบบ่อย                          | วิธีแก้                              |
| ------ | ---------------------------------------- | ------------------------------------ |
| 400    | JSON ไม่ถูกต้อง หรือ parameter ไม่รองรับ | ตรวจ JSON, endpoint, model           |
| 401    | API Key ไม่ถูกต้องหรือไม่ได้ส่ง          | ตรวจ header Authorization            |
| 403    | เครดิตไม่พอหรือไม่มีสิทธิ์ใช้โมเดล       | เติมเครดิต/ตรวจสิทธิ์                |
| 404    | path ไม่ถูกต้อง                          | ตรวจ Base URL และ endpoint           |
| 413    | body หรือไฟล์ใหญ่เกิน                    | ลดขนาดไฟล์หรือ request               |
| 429    | ส่งถี่เกินหรือชน limit                   | รอแล้ว retry แบบ exponential backoff |
| 500    | ระบบภายในผิดพลาด                         | ลองใหม่หรือส่ง Request ID ให้ admin  |
| 503    | ไม่มี channel/model พร้อมใช้งาน          | เลือกโมเดลอื่นหรือลองใหม่            |

ตัวอย่าง retry เมื่อเจอ 429:

```js
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

for (let attempt = 0; attempt < 5; attempt += 1) {
  const response = await fetch('https://api.tinyapi.org/v1/chat/completions', {
    method: 'POST',
    headers: {
      Authorization: 'Bearer sk-xxxxxxxxxxxxxxxx',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      model: 'your-model-id',
      messages: [{ role: 'user', content: 'Hello' }],
    }),
  })

  if (response.status !== 429) {
    console.log(await response.json())
    break
  }

  await delay(1000 * 2 ** attempt)
}
```

### CC-Switch และเครื่องมือที่รองรับ

#### ขั้นตอนทั่วไป

ค่าที่ใช้บ่อย:

```
Provider: TinyAPI
Base URL: https://api.tinyapi.org/v1
API Key: sk-YOUR_API_KEY
```

ขั้นตอน:

1. เปิด CC-Switch หรือเครื่องมือที่ต้องการ
2. เลือก Custom Provider / OpenAI-compatible / Anthropic-compatible
3. วาง Base URL และ API Key
4. เลือกโมเดลจาก TinyAPI
5. บันทึกและทดสอบเรียกใช้งาน

#### Claude Code

ใช้ TinyAPI ผ่าน CC-Switch ได้โดยเพิ่ม custom provider และเลือกโมเดล Claude-compatible จาก TinyAPI

ภาพประกอบ:

![Claude Code 01](https://tinyapi.org/docs-assets/ccswitch-docx/claude-code-01.png) ![Claude Code 02](https://tinyapi.org/docs-assets/ccswitch-docx/claude-code-02.png)

#### Claude Desktop

1. เปิด CC-Switch แล้วเลือก Claude Desktop
2. คัดลอก API Key จาก TinyToken
3. กรอก API Key และ endpoint
4. ดึงรายชื่อโมเดล
5. เลือกโมเดลที่ต้องการ
6. เปิด routing แล้วทดสอบใน Claude Desktop

![Claude Desktop](https://tinyapi.org/docs-assets/ccswitch-docx/claude-desktop-01.png)

#### Codex

1. เปิด CC-Switch แล้วเลือก Codex
2. เพิ่ม Provider ของ TinyAPI
3. วาง API Key
4. เปิด Routing
5. Restart Codex แล้วเลือกโมเดล TinyAPI

![Codex](https://tinyapi.org/docs-assets/ccswitch-docx/codex-01.png)

#### OpenClaw

OpenClaw ใช้เชื่อมต่อ gateway/provider ได้ ให้ตั้งค่า TinyAPI เป็น provider แบบ OpenAI-compatible

```
Base URL: https://api.tinyapi.org/v1
API Key: sk-YOUR_API_KEY
```

![OpenClaw](https://tinyapi.org/docs-assets/openclaw/openclaw-01.png)

#### OpenCode

ตัวอย่าง config สำหรับ TinyAPI:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "tinyapi": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "TinyAPI",
      "options": {
        "baseURL": "https://api.tinyapi.org/v1"
      },
      "models": {
        "gpt-4o": { "name": "gpt-4o" },
        "claude-sonnet-4-6": { "name": "claude-sonnet-4-6" },
        "deepseek-chat": { "name": "deepseek-chat" }
      }
    }
  }
}
```

#### Hermes Agent

Hermes Agent สามารถตั้งค่าให้เรียกผ่าน TinyAPI gateway ได้ โดยใช้ Base URL และ API Key เดียวกับ OpenAI-compatible clients

![Hermes](https://tinyapi.org/docs-assets/hermes/hermes-01-install.png)

### ส่งข้อมูลให้ Admin ตรวจสอบ

ถ้าใช้งานไม่ได้ ให้ส่งข้อมูลนี้ โดยไม่ส่ง API Key เต็ม:

* เวลาเกิดปัญหา
* endpoint ที่เรียก
* ชื่อโมเดล
* HTTP status code
* error.message
* error.code
* Request ID ถ้ามี

### ลิงก์สำคัญ

* เว็บหลัก: <https://tinyapi.org>
* ราคาโมเดล: <https://tinyapi.org/pricing>
* สมัครบัญชี: <https://tinyapi.org/sign-up>
* เข้าสู่ระบบ: <https://tinyapi.org/sign-in>
* API Keys: <https://tinyapi.org/keys>
* Wallet: <https://tinyapi.org/wallet>
* API Base URL: <https://api.tinyapi.org/v1>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tinyapi.org/tinytoken-docs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
