# Anthropic SDK

Source: https://aiand-docs-staging.pages.dev/ja/sdks/anthropic/

ai& は OpenAI 互換に加え、Anthropic 互換エンドポイントも提供します。ベース URL を上書きすれば公式 `anthropic` SDK をそのまま利用できます。

## セットアップ

<Tabs>
<TabItem label="Python">

```bash
pip install anthropic
```

```python
from anthropic import Anthropic

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

</TabItem>
<TabItem label="Node.js">

```bash
npm install @anthropic-ai/sdk
```

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

const client = new Anthropic({
  baseURL: "https://api.aiand.com",
  apiKey: "sk-your-aiand-api-key",
});
```

</TabItem>
</Tabs>

## Messages

```python
response = client.messages.create(
    model="...",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.content[0].text)
```

## ストリーミング

```python
with client.messages.stream(
    model="...",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello"}],
) as stream:
    for text in stream.text_stream:
        print(text, end="")
```

## Files

Anthropic Files API も利用可能です — SDK が送信する `anthropic-version` ヘッダで選択されます:

```python
file = client.beta.files.upload(file=open("cat.png", "rb"))
```

仕組みは [OpenAI と Anthropic の形式](/ja/api/file-shapes/) を参照。

<Aside type="tip">
  ai& に対しては `openai` SDK と `anthropic` SDK を同じプロジェクトで併用できます — API キー、組織、課金はすべて共通です。
</Aside>
