# Claude Sonnet 5.5 API Referensi API lengkap untuk model LLM Claude Sonnet 5.5 dari Anthropic. ## Varian Model API ini mendukung dua varian model Claude Sonnet 5.5: | Model | ID | Deskripsi | |-------|----|-------------| | **Claude Sonnet 5.5 Text to Text** | `claude-sonnet-5.5-text-to-text` | Penalaran teks dan penulisan yang cepat | | **Claude Sonnet 5.5 File Analysis** | `claude-sonnet-5.5-file-analysis` | Analisis berkas dan gambar dengan Claude Sonnet | ## Perbandingan Singkat | Fitur | Teks ke Teks | Analisis Berkas | |---------|--------------|---------------| | Masukan teks | Wajib ✅ | Opsional | | Masukan gambar | Tidak didukung ❌ | Opsional | | Masukan berkas | Tidak didukung ❌ | Opsional | | Respons streaming | SSE | SSE | | `max_tokens` | Opsional | Opsional | ## Claude Sonnet 5.5 Text to Text ### Titik Akhir ```http POST /api/v1/chat/completions ``` ### Parameter Permintaan #### Wajib | Parameter | Tipe | Deskripsi | |-----------|------|-------------| | `model` | string | Harus `"claude-sonnet-5.5-text-to-text"`. | | `messages` | array | Pesan berurutan. Lihat API LLM untuk struktur pesan. | | `stream` | boolean | `true` untuk SSE, `false` untuk satu respons JSON. | #### Dukungan Pesan | Kolom | Teks | Berkas | Gambar | |-------|------|------|-------| | `messages` | Wajib ✅ | Tidak didukung ❌ | Tidak didukung ❌ | #### Opsional | Parameter | Tipe | Rentang | Deskripsi | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 1` | Jumlah token keluaran maksimum. Tidak ada batas maksimum bawaan. | ### Contoh Permintaan ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'claude-sonnet-5.5-text-to-text', messages: [ { role: 'user', content: 'Write a four-line modern poem about a programmer drinking coffee.' } ], stream: true, max_tokens: 500, }) }); ``` ## Claude Sonnet 5.5 File Analysis ### Titik Akhir ```http POST /api/v1/chat/completions ``` ### Parameter Permintaan #### Wajib | Parameter | Tipe | Deskripsi | |-----------|------|-------------| | `model` | string | Harus `"claude-sonnet-5.5-file-analysis"`. | | `messages` | array | Pesan berurutan. Lihat API LLM dan dokumentasi Lampiran Pesan. | | `stream` | boolean | `true` untuk SSE, `false` untuk satu respons JSON. | #### Dukungan Pesan | Kolom | Teks | Berkas | Gambar | |-------|------|------|-------| | `messages` | Opsional | Opsional | Opsional | #### Opsional | Parameter | Tipe | Rentang | Deskripsi | |-----------|------|-------|-------------| | `max_tokens` | integer | `> 1` | Jumlah token keluaran maksimum. Tidak ada batas maksimum bawaan. | ### Contoh Permintaan ```javascript const response = await fetch('https://api.flaq.ai/api/v1/chat/completions', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Accept': 'text/event-stream', 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'claude-sonnet-5.5-file-analysis', messages: [ { role: 'user', content: [ { type: 'text', text: 'Summarize the key points of this PDF.' }, { type: 'file', file: { filename: 'gptproto.pdf', file_data: 'https://tos.gptproto.com/resource/gptproto.pdf' } } ] } ], stream: true, max_tokens: 1000, }) }); ``` ## Format Respons Model LLM Claude Sonnet 5.5 mengembalikan respons penyelesaian yang kompatibel dengan OpenAI. Dengan `stream: true`, respons berupa peristiwa yang dikirim server (SSE); dengan `stream: false`, respons berupa satu objek JSON. ### Respons Berhasil ```text data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{"content":"Here is a concise summary"},"finish_reason":null}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]} data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1710000000,"model":"claude-sonnet-5.5-file-analysis","choices":[],"usage":{"prompt_tokens":12,"completion_tokens":8,"total_tokens":20}} data: [DONE] ``` ### Respons Kesalahan ```text event: error data: {"error":{"message":"Authorization is empty","type":"invalid_request_error","code":"1001","param":null}} ``` ## Praktik Terbaik 1. **Gunakan pesan terstruktur:** Kirim riwayat percakapan melalui `messages[]` alih-alih menggabungkan konteks menjadi satu prompt. 2. **Pilih varian model yang tepat:** Gunakan Text to Text untuk penalaran dan penulisan berbasis teks saja, serta File Analysis jika memerlukan berkas atau gambar. 3. **Atur `max_tokens` sesuai kebutuhan:** Gunakan parameter ini untuk mengontrol panjang keluaran maksimum. 4. **Proses peristiwa SSE:** Tambahkan isi `choices[0].delta.content` untuk tampilan streaming dan perlakukan `data: [DONE]` sebagai penyelesaian yang berhasil. 5. **Kirim hanya masukan yang didukung:** Pada klien saat ini, model teks mengabaikan bagian berkas dan gambar yang tidak didukung.