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

# OpenAI 互換 API

> ベース URL と API キーを変更して、OpenAI SDK から Rock API を利用します。

# OpenAI 互換 API

Rock API は OpenAI 互換エンドポイントを公開しています。既存のクライアントは通常、ベース URL と API キーを変更するだけで移行できます。

## Base URL

```txt theme={null}
https://rockapi.ai/v1
```

## Python

```python theme={null}
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_ROCK_API_KEY",
    base_url="https://rockapi.ai/v1",
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello from Rock API"}],
)

print(response.choices[0].message.content)
```

## Node.js

```js theme={null}
import OpenAI from 'openai'

const client = new OpenAI({
  apiKey: process.env.ROCK_API_KEY,
  baseURL: 'https://rockapi.ai/v1',
})

const response = await client.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Hello from Rock API' }],
})

console.log(response.choices[0].message.content)
```

<Card title="API キーを作成" icon="key" href="https://rockapi.ai/keys">
  登録して[API キー](https://rockapi.ai/keys)を作成し、OpenAI 互換クライアントの接続先を Rock API に向けてください。
</Card>
