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

# EggAPI 文档

> 用一个 API Key 通过 EggAPI 中转公开 nano-banana 图片生成

EggAPI 是面向生产调用的 AI 模型中转平台。你的应用只需要调用一个 REST API，EggAPI 负责鉴权、创建生成任务、选择上游供应商、记录用量、扣除余额、必要时把生成文件写入 R2，并在任务完成后向你的 webhook 回调。

<CardGroup cols={2}>
  <Card title="快速开始" icon="rocket" href="/docs/zh/quickstart">
    创建 API Key、提交生成任务并轮询结果。
  </Card>

  <Card title="鉴权" icon="key" href="/docs/zh/guides/authentication">
    使用后端实际支持的 Bearer Token 格式调用 API。
  </Card>

  <Card title="模型" icon="cube" href="/docs/zh/guides/models">
    查看当前唯一公开发布的模型。
  </Card>

  <Card title="API 参考" icon="code" href="/docs/zh/api-reference/introduction">
    查看响应信封、分页、错误和 OpenAPI 端点。
  </Card>
</CardGroup>

## EggAPI 如何工作

<Steps>
  <Step title="提交">
    使用 `Authorization: Bearer YOUR_API_KEY` 调用 `POST /v1/generate`，传入支持的 `model` 和 `prompt`。
  </Step>

  <Step title="路由">
    Go backend 会校验 API Key，创建任务，并按已配置的 provider route chain 选择上游。
  </Step>

  <Step title="处理">
    Worker 会轮询上游供应商，在路由失败时 fallback，必要时把生成文件上传到 R2，并把任务输出落库。
  </Step>

  <Step title="结算">
    EggAPI 会扣除余额、写入 usage 记录；如果请求里有 `webhook_url`，还会发送带签名的 webhook。
  </Step>
</Steps>

## 第一个请求

```bash theme={null}
curl -X POST https://api.eggapi.ai/v1/generate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "nanobanana",
    "prompt": "A clean product render of a ceramic espresso cup on a walnut desk",
    "aspect_ratio": "16:9",
    "num_outputs": 1,
    "webhook_url": "https://webhook.site/your-webhook-id"
  }'
```

当前公开生成接口会返回一个 `pending` 状态的任务对象。继续用 `GET /v1/tasks/{id}` 查询，直到状态变为 `completed` 或 `failed`。

<Note>
  当前公开目录只暴露 nano-banana。调用 API 时请使用 `nanobanana` 作为 `model` 值。
</Note>


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