# Getting Started with the API: Auth, First Request, SDK Setup

> Source: https://sukruyusufkaya.com/en/learn/claude-ustaligi/api-baslangic
> Updated: 2026-05-11T13:48:34.889Z
> Category: Claude Ustalığı
> Module: 8. Programmatic Claude with the API
**TLDR:** Grab your API key from Anthropic console, install the SDK, run your first call. Python and TypeScript step by step.

> **Bu derste**
>
> Console'da hesap aç, API key oluştur, SDK kur, ilk başarılı çağrını yap. 10 dakika.

# Başlamadan Önce

1. [Anthropic Console](https://console.anthropic.com) hesabı.
2. **API Keys** sayfasından bir key oluştur ve **kasanda sakla** (1Password, AWS Secrets Manager, vs).
3. Kullanım planına göre tier seç (geliştirme için free tier yeterli olabilir).

```bash
$ pip install anthropic
Successfully installed anthropic-x.y.z
```

```bash
$ npm install @anthropic-ai/sdk
+ @anthropic-ai/sdk
added 1 package
```

```bash
$ echo 'ANTHROPIC_API_KEY=sk-ant-...' >> .env.local

```

### Python — ilk çağrı

```python
import os
from anthropic import Anthropic

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])

resp = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=512,
    messages=[
        {"role": "user", "content": "Tek cümleyle: prompt mühendisliği nedir?"},
    ],
)
print(resp.content[0].text)
```

### TypeScript — ilk çağrı

```ts
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic(); // env'den okur

const resp = await client.messages.create({
  model: "claude-sonnet-4-6",
  max_tokens: 512,
  messages: [
    { role: "user", content: "Tek cümleyle: prompt mühendisliği nedir?" },
  ],
});

console.log(resp.content[0].type === "text" ? resp.content[0].text : "");
```

### API key güvenliği — yapılması gerekenler

- **Asla** repoya commit etme.
- **Frontend'e koyma.** Tarayıcı bundle'ında görülürse compromise.
- Server-side proxy üzerinden çağrı yap.
- Rotation politikası: 90 günde bir.
- Per-environment key (dev/staging/prod ayrı).
- Anomali / spike alarmları kur.

### İlk gün sık karşılaşılan hatalar

- **401 Unauthorized:** Key yanlış / süresi dolmuş.
- **400 Bad Request:** Field tipi yanlış (genelde `messages` formatı).
- **429 Rate limited:** Tier limitini aştın → exponential backoff (Ders 8.7).
- **500 / 529:** Geçici hata → otomatik retry.

```python
# Sağlam HTTP wrapper iskeleti
import os, time
from anthropic import Anthropic, APIError, APIStatusError, RateLimitError

client = Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"], timeout=60)

def safe_create(**kwargs):
    for attempt in range(5):
        try:
            return client.messages.create(**kwargs)
        except RateLimitError:
            time.sleep(2 ** attempt)
        except APIStatusError as e:
            if 500 <= e.status_code < 600 and attempt < 4:
                time.sleep(2 ** attempt)
                continue
            raise
```

**Boşluk doldurma egzersizi (text):**
```text
API key _____ koymamalı, _____ proxy üzerinden çağrı yapılmalıdır. 401 hatası genelde _____ kaynaklıdır. 429 hatası _____ aşıldığını ifade eder.
```

> ✋ Kontrol noktası: `q-801-mc1`