# curl

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

ai& のエンドポイントはすべて HTTP + JSON です。`curl` を使ってシェルからテスト、CI からの自動化、SDK を導入する前のサニティチェックなどに利用できます。

## 認証

```bash
export AIAND_API_KEY="sk-your-aiand-api-key"
```

## Chat completion

```bash
curl https://api.aiand.com/v1/chat/completions \
  -H "Authorization: Bearer $AIAND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "...",
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## ストリーミング

`"stream": true` を指定し、バッファリングを無効化する `curl -N` を使います:

```bash
curl -N https://api.aiand.com/v1/chat/completions \
  -H "Authorization: Bearer $AIAND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "...",
    "stream": true,
    "messages": [{"role": "user", "content": "Hello"}]
  }'
```

## ビジョン (file_id)

```bash
curl https://api.aiand.com/v1/chat/completions \
  -H "Authorization: Bearer $AIAND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "...",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is this?"},
        {"type": "file", "file": {"file_id": "file-abc123"}}
      ]
    }]
  }'
```

## ファイルアップロード

```bash
curl https://api.aiand.com/v1/files \
  -H "Authorization: Bearer $AIAND_API_KEY" \
  -F "file=@cat.png" \
  -F "purpose=vision"
```

## Anthropic 形式

`-H "anthropic-version: 2023-06-01"` を付与し、`/v1/messages` を呼び出します。[Messages](/ja/api/messages/) を参照。
