> 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/1-register/9-anthropic-chat.md).

# (9) Anthropic-compatible chat

## Anthropic-compatible chat (Claude)

**Quick Start** · 2026/6/13 · อ่านประมาณ 5 นาที

เรียกใช้งานโมเดล Claude ผ่านรูปแบบ Anthropic Messages API ด้วย endpoint ของ TinyAPI

## Endpoint และ Header

**Method**

```
POST
```

**Endpoint**

```
${apiUrl
```

**Authorization**

```
Authorization: Bearer sk-YOUR_API_KEY
```

**Anthropic version**

```
anthropic-version: 2023-06-01
```

**Content-Type**

```
application/json
```

>

`anthropic-version: 2023-06-01` คือเวอร์ชัน protocol ของ Anthropic Messages API ไม่ใช่ปีของโมเดล และไม่ควรเปลี่ยนเอง

## Parameters หลัก

| PARAMETER   | REQUIRED | DESCRIPTION                                                 |
| ----------- | -------- | ----------------------------------------------------------- |
| model       | ใช่      | Model ID ที่รองรับ anthropic จาก /v1/models                 |
| messages    | ใช่      | รายการข้อความสนทนา role และ content                         |
| max\_tokens | แนะนำ    | จำนวน output token สูงสุดที่อนุญาตให้โมเดลตอบ               |
| system      | ไม่      | คำสั่งหลักหรือบทบาทของโมเดล                                 |
| stream      | ไม่      | true เพื่อรับผลลัพธ์แบบ SSE ทีละส่วน                        |
| temperature | ไม่      | ควบคุมระดับความสุ่มของคำตอบ                                 |
| tools       | ไม่      | รายการเครื่องมือสำหรับ tool use หากโมเดลและ upstream รองรับ |
| thinking    | ไม่      | การตั้งค่า reasoning สำหรับโมเดลที่รองรับ                   |

## Non-streaming

เปลี่ยน `ชื่อโมเดล-Claude` เป็น Model ID จริงจากหน้า รายการโมเดล

**cURL**

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

**Example response**

```json
{
  "id": "msg_xxxxxxxxx",
  "type": "message",
  "role": "assistant",
  "model": "your-claude-model-id",
  "content": [
    {
      "type": "text",
      "text": "Hello. I am ready to help you use TinyAPI."
    }
  ],
  "stop_reason": "end_turn",
  "usage": {
    "input_tokens": 18,
    "output_tokens": 20
  }
}
```

## Streaming

เมื่อกำหนด `stream: true` ระบบจะส่งข้อมูลแบบ SSE ต่อเนื่อง เหมาะกับแชตหรือ Claude Code ที่ต้องแสดงข้อความระหว่างสร้างคำตอบ

**cURL streaming**

```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,
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Write a brief explanation of an API."
      }
    ]
  }'
```

## ข้อควรรู้

* เลือกโมเดลที่มี `anthropic` ใน `supported_endpoint_types`
* สามารถใช้ `x-api-key: sk-...` แทน Authorization กับ endpoint นี้ได้ แต่ตัวอย่างของ TinyAPI ใช้ Authorization เพื่อให้จำง่าย
* ความสามารถ tools, thinking, cache และ parameter ขั้นสูงขึ้นกับโมเดลและ upstream ที่ให้บริการโมเดลนั้น


---

# 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/1-register/9-anthropic-chat.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.
