完成一次图片生成

从选择模型到取得同步或异步图片结果。

图片 Provider 的返回方式并不完全相同。本指南给出的客户端流程同时兼容两种模式。

在模型广场选择图片模型

文生图完整流程

选择图片生成模型,提交 prompt。同步路由直接返回 data;异步路由返回 id 和 status,随后查询任务。

curl
#!/usr/bin/env bash
set -euo pipefail

response=$(curl -fsS https://api.noxgate.net/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"YOUR_MODEL_ID","prompt":"A quiet library at sunrise","n":1}')

task_id=$(printf '%s' "$response" | jq -r '.id // empty')
status=$(printf '%s' "$response" | jq -r '.status // empty')
if [ -n "$task_id" ] && [ -n "$status" ] && [ "$status" != "succeeded" ]; then
  for delay in 2 3 5 8 10 10 10 10; do
    sleep "$delay"
    response=$(curl -fsS "https://api.noxgate.net/v1/images/generations/$task_id" \
      -H "Authorization: Bearer sk-your-api-key")
    status=$(printf '%s' "$response" | jq -r '.status // empty')
    case "$status" in succeeded) break ;; failed|canceled|cancelled) printf '%s
' "$response" >&2; exit 1 ;; esac
  done
fi

printf '%s
' "$response" | jq .

参考图与局部编辑

模型支持时,可增加 image_url 或 image_urls。局部编辑使用 mask_url;网关仍要求 prompt。所有 URL 必须能被上游 Provider 访问。

curl
curl https://api.noxgate.net/v1/images/generations \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"model":"YOUR_MODEL_ID","prompt":"Turn this sketch into a clean product illustration","image_url":"https://example.com/reference.png","mask_url":"https://example.com/mask.png","response_format":"b64_json"}'

识别并保存结果

  • 存在 data 且没有进行中的 status:按同步结果处理。
  • 存在 id 和非终态 status:轮询 GET /v1/images/generations/:task_id。
  • data 项可能返回 url 或 b64_json;URL 可能过期,应及时下载。