> ## 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 Base URL：

```text theme={null}
https://api.eggapi.ai
```

## 1. 获取 API Key

登录 [eggapi.ai](https://eggapi.ai)，进入 dashboard 创建 API Key。公开 API 只接受 `Authorization` 请求头中的 API Key：

```text theme={null}
Authorization: Bearer YOUR_API_KEY
```

## 2. 提交任务

当前文档列出的公开生成模型都是异步模型。`POST /v1/generate` 会返回 `202 Accepted` 和一个任务对象。

<CodeGroup>
  ```bash cURL 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 cinematic product photo of a matte green travel mug",
      "aspect_ratio": "16:9",
      "num_outputs": 1,
      "webhook_url": "https://webhook.site/your-webhook-id"
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.eggapi.ai/v1/generate",
      headers={"Authorization": "Bearer YOUR_API_KEY"},
      json={
          "model": "nanobanana",
          "prompt": "A cinematic product photo of a matte green travel mug",
          "aspect_ratio": "16:9",
          "num_outputs": 1,
          "webhook_url": "https://webhook.site/your-webhook-id",
      },
  )

  response.raise_for_status()
  task = response.json()["data"]
  print(task["id"])
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api.eggapi.ai/v1/generate", {
    method: "POST",
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "nanobanana",
      prompt: "A cinematic product photo of a matte green travel mug",
      aspect_ratio: "16:9",
      num_outputs: 1,
      webhook_url: "https://webhook.site/your-webhook-id"
    })
  });

  if (!response.ok) throw new Error(await response.text());
  const { data: task } = await response.json();
  console.log(task.id);
  ```
</CodeGroup>

示例响应：

```json theme={null}
{
  "data": {
    "id": "gen_abc123def456",
    "status": "pending",
    "model": "nanobanana",
    "type": "image_generate",
    "cost": "$0.00",
    "created_at": "2026-05-08T10:30:00Z"
  },
  "error": null
}
```

## 3. 轮询任务

使用响应里的任务 ID 查询状态：

```bash theme={null}
curl https://api.eggapi.ai/v1/tasks/gen_abc123def456 \
  -H "Authorization: Bearer YOUR_API_KEY"
```

完成后的响应示例：

```json theme={null}
{
  "data": {
    "id": "gen_abc123def456",
    "status": "completed",
    "model": "nanobanana",
    "type": "image_generate",
    "output": {
      "url": "https://file.eggapi.ai/images/gen_abc123def456/0.png",
      "urls": ["https://file.eggapi.ai/images/gen_abc123def456/0.png"]
    },
    "cost": "$0.0100",
    "created_at": "2026-05-08T10:30:00Z",
    "started_at": "2026-05-08T10:30:01Z",
    "completed_at": "2026-05-08T10:30:12Z"
  },
  "error": null
}
```

## 4. 查看用量

用量接口必须使用 API Key：

```bash theme={null}
curl https://api.eggapi.ai/v1/usage/summary \
  -H "Authorization: Bearer YOUR_API_KEY"
```

示例响应：

```json theme={null}
{
  "data": [
    {
      "model": "nanobanana",
      "total_units": 1,
      "total_cost": "$0.0100",
      "request_count": 1
    }
  ],
  "error": null
}
```

## 下一步

<CardGroup cols={2}>
  <Card title="模型" icon="cube" href="/docs/zh/guides/models">
    选择模型 ID 和参数。
  </Card>

  <Card title="异步任务" icon="clock" href="/docs/zh/guides/async-tasks">
    了解轮询、webhook 和重试处理。
  </Card>
</CardGroup>


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