> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# はじめに

## インストール

任意の言語からHTTPまたはWebSocketリクエストを通じてAPIを利用できます。また、公式Pythonバインディングまたは公式Node.jsライブラリも利用できます。

公式Pythonバインディングをインストールするには、次のコマンドを実行します。

```bash
pip install elevenlabs
```

公式Node.jsライブラリをインストールするには、Node.jsプロジェクトディレクトリで次のコマンドを実行します。

```bash
npm install @elevenlabs/elevenlabs-js
```

## 生成コストの追跡

レスポンスヘッダーにアクセスして、文字数コストを含む生成メタデータを取得します。

#### Python

```python
from elevenlabs.client import ElevenLabs

client = ElevenLabs(api_key="your_api_key")

# Get raw response with headers
response = client.text_to_speech.with_raw_response.convert(
    text="Hello, world!",
    voice_id="voice_id"
)

# Access character cost from headers
char_cost = response.headers.get("character-cost")

# Optionally store these for debugging
request_id = response.headers.get("request-id")
trace_id = response.headers.get("x-trace-id")

audio_data = response.data
```

#### JavaScript

```typescript
import { ElevenLabsClient } from '@elevenlabs/elevenlabs-js';

const client = new ElevenLabsClient({ apiKey: 'your_api_key' });

// Get raw response with headers
const { data, rawResponse } = await client.textToSpeech
  .convert('voice_id', {
    text: 'Hello, world!',
    modelId: 'eleven_v4',
  })
  .withRawResponse();

// Access character cost from headers
const charCost = rawResponse.headers.get('character-cost');

// Optionally store these for debugging
const requestId = rawResponse.headers.get('request-id');
const traceId = rawResponse.headers.get('x-trace-id');

const audioData = data;
```

生のレスポンスでは、次の項目にアクセスできます。

* レスポンスデータ：実際のAPIレスポンスの内容
* HTTPヘッダー：文字数コストやリクエストIDを含むメタデータ