Skip to content

API 参考

Base URL

txt
https://api.pixapi.ai

通用 headers

Header必填说明
AuthorizationBearer $PIXAPI_KEY
Content-TypeJSON 请求必填生成请求使用 application/json。携带文件的图片编辑请求使用 multipart/form-data

Pixapi 模型请求使用 OpenAI 兼容字段:modelpromptnsize,以及模型支持的 quality 等控制项。旧 Nano Banana 兼容请求格式仅保留在过渡格式中。

同步与异步模式

图片请求支持标准 OpenAI-compatible 同步 endpoint:POST /v1/images/generationsPOST /v1/images/edits

耗时图片任务也可以使用 /v1/async/* 下的独立异步 endpoint。视频生成只支持异步创建,必须通过 POST /v1/async/videos/generations 提交。Pixapi 会立即返回任务 id。使用 GET /v1/tasks/{id} 轮询,直到任务进入 completedfailed

工作负载同步 endpoint异步 endpoint
文生图POST /v1/images/generationsPOST /v1/async/images/generations
图片编辑POST /v1/images/editsPOST /v1/async/images/edits
工作负载仅异步 endpoint
视频生成POST /v1/async/videos/generations

不要再使用 ?async=true"async": true。完整集成流程见异步媒体任务

请求示例

bash
curl https://api.pixapi.ai/v1/images/generations \
  -H "Authorization: Bearer $PIXAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-pro-image-preview",
    "prompt": "A cinematic product photo of a ceramic coffee cup",
    "n": 1,
    "size": "1024x1024"
  }'
py
import os
import requests

response = requests.post(
    "https://api.pixapi.ai/v1/images/generations",
    headers={
        "Authorization": f"Bearer {os.environ['PIXAPI_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "model": "gemini-3-pro-image-preview",
        "prompt": "A cinematic product photo of a ceramic coffee cup",
        "n": 1,
        "size": "1024x1024",
    },
)

response.raise_for_status()
result = response.json()
print(result["data"][0]["url"])
js
const response = await fetch('https://api.pixapi.ai/v1/images/generations', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.PIXAPI_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: 'gemini-3-pro-image-preview',
    prompt: 'A cinematic product photo of a ceramic coffee cup',
    n: 1,
    size: '1024x1024',
  }),
});

if (!response.ok) {
  throw new Error(await response.text());
}

const result = await response.json();
console.log(result.data?.[0]?.url ?? result);
go
package main

import (
  "bytes"
  "fmt"
  "io"
  "net/http"
  "os"
)

func main() {
  body := []byte(`{
    "model": "gemini-3-pro-image-preview",
    "prompt": "A cinematic product photo of a ceramic coffee cup",
    "n": 1,
    "size": "1024x1024"
  }`)

  req, err := http.NewRequest(
    "POST",
    "https://api.pixapi.ai/v1/images/generations",
    bytes.NewBuffer(body),
  )
  if err != nil {
    panic(err)
  }
  req.Header.Set("Authorization", "Bearer "+os.Getenv("PIXAPI_KEY"))
  req.Header.Set("Content-Type", "application/json")

  resp, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()

  result, _ := io.ReadAll(resp.Body)
  fmt.Println(string(result))
}
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

class PixapiExample {
  public static void main(String[] args) throws Exception {
    String body = """
      {
        "model": "gemini-3-pro-image-preview",
        "prompt": "A cinematic product photo of a ceramic coffee cup",
        "n": 1,
        "size": "1024x1024"
      }
      """;

    HttpRequest request = HttpRequest.newBuilder()
      .uri(URI.create("https://api.pixapi.ai/v1/images/generations"))
      .header("Authorization", "Bearer " + System.getenv("PIXAPI_KEY"))
      .header("Content-Type", "application/json")
      .POST(HttpRequest.BodyPublishers.ofString(body))
      .build();

    HttpResponse<String> response = HttpClient.newHttpClient()
      .send(request, HttpResponse.BodyHandlers.ofString());

    System.out.println(response.body());
  }
}
php
<?php
$payload = json_encode([
  "model" => "gemini-3-pro-image-preview",
  "prompt" => "A cinematic product photo of a ceramic coffee cup",
  "n" => 1,
  "size" => "1024x1024",
]);

$ch = curl_init("https://api.pixapi.ai/v1/images/generations");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("PIXAPI_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => $payload,
]);

$response = curl_exec($ch);
curl_close($ch);

echo $response;

图片生成

http
POST /v1/images/generations

使用 OpenAI 兼容请求字段,从提示词生成一张或多张图片。

字段类型必填说明
modelstring图片模型 id,例如 gemini-3-pro-image-previewgpt-image-2。也支持 nano-banananano-banana-2nano-banana-pro 等已记录的别名。
promptstring描述目标图片的文本提示词。
nnumber返回图片数量,未传时默认 1
sizestring输出尺寸,例如 auto1024x10241536x10241024x1536,或模型支持的其他 WIDTHxHEIGHT
qualitystring模型支持时可设置质量档位,例如 lowmediumhighauto
response_formatstring模型支持时可选 urlb64_json

图片编辑

http
POST /v1/images/edits

使用 OpenAI 兼容的 multipart 表单字段编辑一张或多张输入图片。

字段类型必填说明
modelstring支持编辑的图片模型 id,例如 gemini-3-pro-image-previewgpt-image-2。也支持 nano-banananano-banana-2nano-banana-pro 等已记录的别名。
promptstring描述编辑意图的文本指令。
imagefile 或 file[]输入图片文件;模型支持多参考图时,可发送多个 image 字段。
nnumber返回图片数量。
sizestring输出尺寸,例如 1024x1024auto
qualitystring模型支持时可设置质量档位。
response_formatstring模型支持时可选 urlb64_json
bash
curl https://api.pixapi.ai/v1/images/edits \
  -H "Authorization: Bearer $PIXAPI_KEY" \
  -F "model=gemini-3-pro-image-preview" \
  -F "prompt=Place the product on a warm studio background" \
  -F "image=@product.png" \
  -F "n=1" \
  -F "size=1024x1024"

成功的图片响应使用 OpenAI 图片响应结构:

json
{
  "created": 1766880000,
  "data": [
    {
      "url": "https://cdn.pixapi.ai/generated/image.png"
    }
  ]
}

response_formatb64_json 时,返回项包含 b64_json 而不是 url

异步媒体提交

http
POST /v1/async/images/generations
POST /v1/async/images/edits
POST /v1/async/videos/generations

以后台任务方式提交耗时媒体请求。异步图片 endpoint 接受与对应图片生成、图片编辑 endpoint 相同的请求字段。视频生成只通过异步视频 endpoint 提供。

视频提交使用 OpenAI 风格 JSON payload:

字段类型必填说明
modelstring视频模型 id,例如 veowan
promptstring描述场景、运动和镜头的文本提示词。
durationnumber请求的视频时长,单位秒。
sizestring输出尺寸或比例预设,例如 1280x720720x128016:9
input_imagestring图生视频时可传输入图片 URL。
json
{
  "status": "submitted",
  "id": "task_01KPQ7J7DWB7QZ3WCEK3YVPBRA",
  "progress": 0,
  "created_at": 1703884800,
  "model": "gemini-3.1-flash-image-preview"
}
字段说明
statusPixapi 接收任务后返回 submitted
id用于 GET /v1/tasks/{id} 的任务 id。
progress0100 的整数进度。
created_at任务提交时的 Unix 时间戳。
model请求中的模型 id。

媒体任务

http
GET /v1/tasks/{id}

查询异步图片或视频任务。

json
{
  "id": "xxx",
  "status": "completed",
  "credits_cost": 1.5,
  "model": "sora-2",
  "progress": 100,
  "result": {
    "type": "video",
    "data": [
      {
        "url": "https://xxx.xxx"
      }
    ]
  },
  "created": 1763088289,
  "completed": 1763088308
}
字段说明
id异步创建请求返回的任务 id。
statussubmittedprocessingcompletedfailed
credits_cost任务完成后扣除的积分。
model任务使用的模型 id。
progress0100 的整数进度。
result.type输出媒体类型,例如 imagevideo
result.data生成媒体列表;可用时每一项包含 url
created任务创建时的 Unix 时间戳。
completed任务完成时的 Unix 时间戳。

错误格式

json
{
  "error": {
    "code": 400,
    "message": "xxx",
    "type": "invalid_request_error"
  }
}

模型列表

http
GET /v1/models

返回当前账户可用的模型 id 和能力。

模型列表返回规范模型 id。nano-banana-2 等别名仍可在生成和编辑请求中使用,具体以模型页记录为准。

json
{
  "object": "list",
  "data": [
    {
      "id": "gemini-3-pro-image-preview",
      "object": "model",
      "category": "image",
      "capabilities": ["text-to-image", "image-to-image"]
    }
  ]
}