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

# 路径 1 · OpenAI 兼容

> POST /v1/images/generations · 已有 OpenAI 代码改 base_url 即用

已经在用 OpenAI 的生图接口？优先只改 `base_url` 和 `api_key`。图片生成主路径是：

```
POST https://tapapi.ai/v1/images/generations
```

## 字段

| 字段                | 类型     |  必填 | 说明                                        |
| ----------------- | ------ | :-: | ----------------------------------------- |
| `model`           | string |  ✅  | 模型名（见 [模型清单](/image-generation/overview)） |
| `prompt`          | string |  ✅  | 提示词                                       |
| `n`               | int    |  —  | 生成张数（默认 1）                                |
| `size`            | string |  —  | 如 `1024x1024`                             |
| `quality`         | string |  —  | 部分模型支持                                    |
| `response_format` | enum   |  —  | `url`（默认）/ `b64_json`                     |
| `output_format`   | enum   |  —  | 部分模型支持 `png` / `jpeg` / `webp`            |

## 示例

<CodeGroup>
  ```python Python theme={null}
  from openai import OpenAI

  client = OpenAI(api_key="sk-xxx", base_url="https://tapapi.ai/v1")

  resp = client.images.generate(
      model="z-image-turbo",
      prompt="电商商品图：白底银项链特写",
      n=1,
      size="1024x1024",
      response_format="url",
  )

  if not resp.data:
      raise RuntimeError("No image returned")

  first = resp.data[0]
  print(first.url or first.b64_json)
  ```

  ```javascript Node.js theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({ apiKey: "sk-xxx", baseURL: "https://tapapi.ai/v1" });

  const resp = await client.images.generate({
    model: "z-image-turbo",
    prompt: "电商商品图：白底银项链特写",
    n: 1,
    size: "1024x1024",
    response_format: "url",
  });

  if (!resp.data?.length) {
    throw new Error("No image returned");
  }

  console.log(resp.data[0].url ?? resp.data[0].b64_json);
  ```
</CodeGroup>

## 迁移检查

* `base_url` 使用 `https://tapapi.ai/v1`
* `Authorization` 使用 Tapapi API Key
* `size` 使用小写字母 `x`，例如 `1024x1024`
* `n` 会影响成本，批量前先做小样本测试
* 返回 `url` 时建议转存，返回 `b64_json` 时注意响应体体积
* 不要只写死 `resp.data[0].url`，生产代码要兼容 `url` 和 `b64_json`
* 日志保存 HTTP 状态码、模型、`data.length`、错误对象和 `X-Oneapi-Request-Id`

<Warning>`image_urls`、多参考图、webhook 异步回调不是当前 OpenAI-compatible 图片生成路径的稳定字段。需要图片输入能力时先看 [图生图](/image-generation/image-to-image)、[多参考图](/image-generation/multi-reference) 和 [图片编辑](/image-generation/image-editing)，不要直接写入生产请求。</Warning>

更多语言示例见 [Python](/integrations/python)、[Node.js / TypeScript](/integrations/node-typescript)、[PHP / Laravel](/integrations/php-laravel) 和 [HTTP REST](/integrations/http-rest)。
