Skip to content

GPT Image 2

gpt-image-2 支持文生图和图片编辑,并使用 OpenAI 兼容的 sizequality 控制项。

API 形式

操作Endpoint模式
图片生成POST /v1/images/generations同步
图片生成任务POST /v1/async/images/generations异步
图片编辑POST /v1/images/edits同步
图片编辑任务POST /v1/async/images/edits异步

价格

每张图片的积分由输出尺寸档位和质量档位决定。quality=autohigh 计费,size=auto 默认进入 1K 档。

尺寸档长边lowmediumhigh / auto
1K<= 1536px1414
2K<= 2048px21767
4K<= 3840px434133

请求显示的 costCredits 等于矩阵值乘以 n

示例

bash
curl https://api.pixapi.ai/v1/images/generations \
  -H "Authorization: Bearer $PIXAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "gpt-image-2",
  "prompt": "A polished product photo of a ceramic coffee cup",
  "n": 1,
  "size": "1024x1024",
  "quality": "high"
}'
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": "gpt-image-2",
    "prompt": "A polished product photo of a ceramic coffee cup",
    "n": 1,
    "size": "1024x1024",
    "quality": "high"
},
)
response.raise_for_status()
print(response.json())
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": "gpt-image-2",
  "prompt": "A polished product photo of a ceramic coffee cup",
  "n": 1,
  "size": "1024x1024",
  "quality": "high"
}),
});

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

console.log(await response.json());
go
package main

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

func main() {
  body := []byte(`{
  "model": "gpt-image-2",
  "prompt": "A polished product photo of a ceramic coffee cup",
  "n": 1,
  "size": "1024x1024",
  "quality": "high"
}`)

  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))
}

全部请求字段和自定义尺寸限制见 GPT Image