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

# OpenAI SDK

> 将 OpenAI 官方 SDK 与 Phaseo 搭配使用。

如果你的应用已经通过 TypeScript、JavaScript 或 Python 调用 OpenAI，请使用本指南。只需更改 API 密钥、基础 URL 和模型 ID。

## TypeScript

```bash theme={null}
npm install openai
```

```ts theme={null}
import OpenAI from "openai";

const client = new OpenAI({
	apiKey: process.env.PHASEO_API_KEY,
	baseURL: "https://api.phaseo.app/v1",
});

const response = await client.responses.create({
	model: "openai/gpt-5-nano",
	input: "Write one sentence about reliable model routing.",
});

console.log(response.output_text);
```

## Python

```bash theme={null}
pip install openai
```

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

client = OpenAI(
    api_key=os.environ["PHASEO_API_KEY"],
    base_url="https://api.phaseo.app/v1",
)

response = client.responses.create(
    model="openai/gpt-5-nano",
    input="Write one sentence about reliable model routing.",
)

print(response.output_text)
```

## Chat Completions

较旧的库可能仍会调用 Chat Completions：

```ts theme={null}
const completion = await client.chat.completions.create({
	model: "openai/gpt-5-nano",
	messages: [{ role: "user", content: "Reply with only: ok" }],
});
```

## 注意事项

* 使用 Phaseo 模型 ID，包括 `openai/`、`anthropic/` 或 `google/` 等提供商前缀。
* 服务器工具使用 Phaseo 工具名称，例如 `phaseo:web_search`。
* 对于 Anthropic 原生客户端，请改用 [Anthropic SDK](./anthropic-sdk.mdx) 指南。

## 相关页面

* [Responses API](../../api-reference/endpoint/responses.mdx)
* [Chat Completions](../../api-reference/endpoint/chat-completions.mdx)
* [服务器工具](../server-tools/index.mdx)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.