> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Anthropic SDK

> Claude-native Messages API uyumluluğu için TokenLab'yı Anthropic SDK ile kullanın

## Genel Bakış

TokenLab, doğal Anthropic **Messages API** yolunu destekler; böylece Claude modelleri için resmi Anthropic SDK'yı doğrudan kullanabilirsiniz.

<Note>
  Anthropic SDK için base URL olarak `https://api.tokenlab.sh` kullanın; `/v1` ekini kendiniz eklemeyin.
</Note>

<Note>
  **Tür**: Native SDK

  **Birincil yol**: Anthropic-native

  **Destek seviyesi**: Güçlü native path
</Note>

Belgelenen SDK yolları arasında bu, Claude yerel özellikleri için en güçlü şekilde desteklenen TokenLab yollarından biridir.

## Kurulum

<CodeGroup>
  ```bash Python theme={null}
  pip install anthropic
  ```

  ```bash JavaScript theme={null}
  npm install @anthropic-ai/sdk
  ```
</CodeGroup>

## Client'ı Yapılandırın

<CodeGroup>
  ```python Python theme={null}
  from anthropic import Anthropic

  client = Anthropic(
      api_key="sk-your-tokenlab-key",
      base_url="https://api.tokenlab.sh",
  )
  ```

  ```javascript JavaScript theme={null}
  import Anthropic from '@anthropic-ai/sdk';

  const client = new Anthropic({
    apiKey: 'sk-your-tokenlab-key',
    baseURL: 'https://api.tokenlab.sh',
  });
  ```
</CodeGroup>

## Temel Kullanım

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[
        {"role": "user", "content": "Explain TokenLab in one sentence."}
    ]
)

print(message.content[0].text)
```

## Streaming

```python theme={null}
with client.messages.stream(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Write a short poem about coding."}]
) as stream:
    for text in stream.text_stream:
        print(text, end="", flush=True)
```

## Vision

```python theme={null}
import base64

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What's in this image?"},
            {
                "type": "image",
                "source": {
                    "type": "url",
                    "url": "https://example.com/image.jpg"
                }
            }
        ]
    }]
)

with open("image.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode()

message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "Describe this image"},
            {
                "type": "image",
                "source": {
                    "type": "base64",
                    "media_type": "image/png",
                    "data": image_data
                }
            }
        ]
    }]
)
```

## Tool Kullanımı

```python theme={null}
message = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    tools=[{
        "name": "get_weather",
        "description": "Get the weather for a location",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            },
            "required": ["location"]
        }
    }],
    messages=[{"role": "user", "content": "What's the weather in Tokyo?"}]
)

for block in message.content:
    if block.type == "tool_use":
        print(block.name)
        print(block.input)
```

## Genişletilmiş Düşünme

```python theme={null}
message = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000
    },
    messages=[{"role": "user", "content": "Solve this complex problem step by step."}]
)

for block in message.content:
    if block.type == "thinking":
        print(block.thinking)
    elif block.type == "text":
        print(block.text)
```

## Önerilen Claude Modelleri

| Model               | En Uygun Olduğu Alan                |
| ------------------- | ----------------------------------- |
| `claude-opus-4-6`   | Derin muhakeme, uzun biçimli analiz |
| `claude-sonnet-4-6` | Kodlama, genel asistan görevleri    |
| `claude-haiku-4-5`  | Hızlı, hafif yanıtlar               |

## Sorun Giderme

<AccordionGroup>
  <Accordion title="Yanlış Base URL">
    * `https://api.tokenlab.sh` kullanın
    * Anthropic SDK'yı yapılandırırken `/v1` ekini manuel olarak eklemeyin
  </Accordion>

  <Accordion title="Kimlik Doğrulama Başarısız Oldu">
    * TokenLab API anahtarınızın `sk-` ile başladığını kontrol edin
    * Anahtarın TokenLab dashboard içinde aktif olduğunu doğrulayın
    * Özel header'ları manuel olarak eklemek yerine auth header'ını Anthropic SDK'nın yönetmesine izin verin
  </Accordion>

  <Accordion title="Model Bulunamadı">
    * Claude model adını tam olarak doğrulayın
    * TokenLab model kataloğundaki güncel kullanılabilirliği kontrol edin
  </Accordion>
</AccordionGroup>
