# Krea 3

> 使用最多 8 张参考图进行编辑或合成，输出一张 1K 或 2K 图片。

- 模型页: https://yir.ai/zh/models/krea-3
- 模型 ID: `krea/krea-3`
- 计费：按实际执行渠道的上游计费收取；上游未计费的尝试不收费。

## 价格

同一输出规格下各渠道的当前公开价；官方价为参考。实际按执行渠道计费，故障转移时可能切换渠道。

| 输出规格 | 渠道 | 公开价 |
|---|---|---|
| 1K | FAL | ≈$0.025 / 张 |
| 2K | FAL | ≈$0.10 / 张 |

## 参数

- 操作: `generate_image`

| 参数 | 可选值 | 默认值 |
|---|---|---|
| `input` | image | image |
| `resolution` | 1K / 2K | 1K |
| `aspect_ratio` | 1:1 / 4:3 / 3:4 / 16:9 / 9:16 | 1:1 |

## 接入

两种方式任选：新项目用官方 SDK；已按 OpenAI 协议对接的项目换 Base URL 即可。

### 官方 SDK（TypeScript）

SDK 调用 Standard API（https://gateway.yir.ai），支持提交、等待和获取结果，另有 Go SDK。 https://yir.ai/zh/docs/integrations/sdk

```bash
pnpm add @yir-ai/sdk
```

```ts
// Replace https://example.com/your-reference-image.png with your publicly accessible HTTPS image URL.
import { createNodeYirClient } from "@yir-ai/sdk/server";

// Reads YIR_API_KEY from the environment by default: process.env.YIR_API_KEY
const client = createNodeYirClient();

// 1. Submit an image generation job
const job = await client.submitImage({
  model: "krea/krea-3",
  input: {
    type: "image",
    prompt: "为一款柑橘气泡水设计产品海报：透明玻璃瓶与鲜橙，奶油色背景，柔和自然光，清晰的产品标签",
    references: [{ role: "reference_image", ...{ url: "https://example.com/your-reference-image.png" } }],
  },
  parameters: {
    resolution: "1K",
    aspect_ratio: "1:1",
    n: 1,
  },
});

// 2. Wait for the job to finish and deliver its result
const result = await client.waitForJob(job.id);
console.log("Delivered files:", result.result);
if (result.result && "files" in result.result) {
  for (const file of result.result.files) {
    console.log("->", file.url);
  }
}
```

### OpenAI 兼容 API

OpenAI Images 与 Sora Videos 协议，适用于 OpenAI SDK 和 new-api 等网关；不支持对话。 https://yir.ai/zh/docs/integrations/openai-compatibility

- OpenAI SDK base_url: `https://gateway.yir.ai/openai/v1`
- new-api 渠道 Base URL（渠道类型 OpenAI）: `https://gateway.yir.ai/openai`
- 模型 ID: `krea/krea-3`

```bash
# Replace https://example.com/your-reference-image.png with your publicly accessible HTTPS image URL.
curl https://gateway.yir.ai/openai/v1/images/generations \
  -H "Authorization: Bearer $YIR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "krea/krea-3",
    "prompt": "为一款柑橘气泡水设计产品海报：透明玻璃瓶与鲜橙，奶油色背景，柔和自然光，清晰的产品标签",
    "resolution": "1K",
    "aspect_ratio": "1:1",
    "images": [
      {
        "image_url": "https://example.com/your-reference-image.png"
      }
    ]
  }'
```

## 接入须知

- 使用 Authorization: Bearer $YIR_API_KEY 鉴权；Key 只放服务端环境变量，不进浏览器代码、仓库、提示词或日志。
- 任务是异步的：提交后保存 Job ID，等待终态再读取结果；处理失败与取消。
- 安全重试时复用同一个幂等键和请求，不要在结果未知时盲目重新提交。
- 结果链接是临时的，需要长期保存请自行转存。

## 链接

- [快速开始](https://yir.ai/zh/docs/getting-started/quickstart)
- [API 参考](https://yir.ai/zh/docs/reference)
- [llms.txt](https://yir.ai/llms.txt)
