> ## 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.

# API tương thích OpenAI

> Dùng Rock API với OpenAI SDK bằng cách đổi base URL và API key.

# API tương thích OpenAI

Rock API cung cấp endpoint tương thích OpenAI, nên client hiện có thường có thể chuyển sang bằng cách đổi base URL và API key.

## 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="Tạo API key" icon="key" href="https://rockapi.ai/keys">
  Đăng ký, tạo [API key](https://rockapi.ai/keys), rồi trỏ client tương thích OpenAI đến Rock API.
</Card>
