gpt-image-2.5-flare

最后更新:2026-11-14

POSThttps://www.sagelib.com/images/generations

gpt-image-2.5-flare 模型的图像生成接口,OpenAI兼容,支持文生图、图像参数配置等。

接口鉴权方式请参考:API接入与鉴权

请求参数

请求头

参数名称 描述
*Authorization string 认证令牌
*Content-Type string 内容类型

Body 参数

参数名称 描述
*prompt string 可选值:- (up to 32000 characters)
图像生成的文本描述提示词,描述期望的图像内容与风格
model string 默认值:gpt-image-2.5-flare
可选值:gpt-image-2.5-flare / gpt-image-2.5-sunburst
模型名称
n integer 默认值:1
可选值:1-10
一次请求生成的图像数量,响应 data 数组长度与之一致
size string 默认值:1024x1024
可选值:auto / 1024x1024 / 1536x1024 / 1024x1536 (+ custom WxH)
输出图像分辨率,支持枚举档位与自定义 WxH 像素
quality string 默认值:auto
可选值:auto / low / medium / high / xhigh / max
图像质量档位
background string 默认值:auto
可选值:transparent / opaque / auto
背景处理方式,transparent 生成透明背景(png/webp 下生效)
output_format string 默认值:png
可选值:png / jpeg / webp
输出图像编码格式,transparent 背景须配 png 或 webp
output_compression integer 默认值:100
可选值:0-100
有损压缩率百分比,仅 jpeg/webp 生效
partial_images integer 默认值:0
可选值:0-3
流式模式下返回的中间预览图数量,须配合 stream=true 使用
stream boolean 默认值:false
可选值:true、false
是否流式返回,true 时以 SSE 事件流逐帧返回图像数据
user string 终端用户标识符,用于滥用追踪,不影响生成内容
moderation string 默认值:auto
可选值:low / auto
内容审核级别,low 启用低强度审核

请求示例

curl -v 'https://www.sagelib.com/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024"
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024"
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            // Use ofInputStream to handle the streaming response
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        // Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024"
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    // Pretty-print the returned JSON data
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024",
    "stream": true
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024",
    "stream": True
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024",
                "stream": true
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            // Use ofInputStream to handle the streaming response
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        // Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024",
                "stream": true
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    // Pretty-print the returned JSON data
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "n": 2,
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "n": 2,
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "n": 2,
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            // Use ofInputStream to handle the streaming response
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        // Tip: you can bring in Gson or Jackson here to parse the JSON in data and extract delta.content
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "n": 2,
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    // Pretty-print the returned JSON data
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}

响应参数

Body 参数

参数名称 描述
created integer 生成时间戳(Unix 秒)
model string 实际使用的模型名
data array 图像数组,长度 = n
    b64_json string Base64 编码的图像数据(本模型系列不返回 url 字段)
usage object Token 使用统计
    input_tokens integer 输入 token 数(input_tokens_details 含 image_tokens/text_tokens 细分)
    output_tokens integer 输出 token 数(output_tokens_details 含 image_tokens 细分)
    total_tokens integer 总 token 数
size string 实际输出尺寸
quality string 实际质量档位
background string 实际背景处理方式
output_format string 实际输出格式
POSThttps://www.sagelib.com/openai/images/generations

gpt-image-2.5-flare 模型的图像生成接口,OpenAI直连模式(URL 前缀 /openai),支持文生图、流式返回、多图生成等。

接口鉴权方式请参考:API接入与鉴权

请求参数

请求头

参数名称 描述
*Authorization string 鉴权令牌,格式为 Bearer ${AIGATEWAY_TOKEN}
*Content-Type string 可选值:application/json
application/json

Body 参数

参数名称 描述
*prompt string 可选值:- (up to 32000 characters)
图像生成的文本描述提示词,描述期望的图像内容与风格
model string 默认值:gpt-image-2.5-flare
可选值:gpt-image-2.5-flare / gpt-image-2.5-sunburst
模型名称,取值 gpt-image-2.5-flare / gpt-image-2.5-sunburst
n integer 默认值:1
可选值:1-10
一次请求生成的图像数量,响应 data 数组长度与之一致
size string 默认值:1024x1024
可选值:auto / 1024x1024 / 1536x1024 / 1024x1536 (+ custom WxH)
输出图像分辨率,支持枚举档位与自定义 WxH 像素
quality string 默认值:auto
可选值:auto / low / medium / high / xhigh / max
图像质量档位
background string 默认值:auto
可选值:transparent / opaque / auto
背景处理方式,transparent 生成透明背景(png/webp 下生效)
output_format string 默认值:png
可选值:png / jpeg / webp
输出图像编码格式,transparent 背景须配 png 或 webp
output_compression integer 默认值:100
可选值:0-100
有损压缩率百分比,仅 jpeg/webp 生效
partial_images integer 默认值:0
可选值:0-3
流式模式下返回的中间预览图数量,须配合 stream=true 使用
stream boolean 默认值:false
可选值:true、false
是否流式返回,true 时以 SSE 事件流逐帧返回图像数据
user string 终端用户标识符,用于滥用追踪,不影响生成内容
moderation string 默认值:auto
可选值:low / auto
内容审核级别,low 启用低强度审核

请求示例

curl -v 'https://www.sagelib.com/openai/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024"
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/openai/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024"
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/openai/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/openai/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024"
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/openai/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024",
    "stream": true
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/openai/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
    "size": "1024x1024",
    "stream": True
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/openai/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024",
                "stream": true
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/openai/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers",
                "size": "1024x1024",
                "stream": true
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}
curl -v 'https://www.sagelib.com/openai/images/generations' \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.5-flare",
    "n": 2,
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
  }'
import json
import requests

# Configure base variables
base_url = "https://www.sagelib.com"  # 把 base_url 换成你的网关地址 https://www.sagelib.com
api_key = "***"  # Replace with your Bearer token

url = f"https://www.sagelib.com/openai/images/generations"

headers = {
    "Authorization": f"Bearer {api_key}",
    "Content-Type": "application/json",
}

data = {
    "model": "gpt-image-2.5-flare",
    "n": 2,
    "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
}

# Send the POST request
response = requests.post(url, headers=headers, json=data)

# Print the status code and the returned JSON data
print(f"Status Code: {response.status_code}")
try:
    print(json.dumps(response.json(), indent=2, ensure_ascii=False))
except Exception:
    print(response.text)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class LlmStreamClient {
    public static void main(String[] args) {
        String baseUrl = "https://www.sagelib.com";
        String apiKey = "***";
        String url = "https://www.sagelib.com/openai/images/generations";

        String jsonRequestBody = """
            {
                "model": "gpt-image-2.5-flare",
                "n": 2,
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonRequestBody))
                .build();

        try {
            HttpResponse<java.io.InputStream> response = client.send(request, HttpResponse.BodyHandlers.ofInputStream());
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.body()))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    line = line.trim();
                    if (line.startsWith("data:")) {
                        String data = line.substring(5).trim();
                        if ("[DONE]".equals(data)) break;
                        System.out.println("Received stream chunk: " + data);
                    }
                }
            }
        } catch (Exception e) { e.printStackTrace(); }
    }
}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    baseUrl := "https://www.sagelib.com"
    apiKey := "***"
    url := "https://www.sagelib.com/openai/images/generations"

    jsonRequestBody := `
            {
                "model": "gpt-image-2.5-flare",
                "n": 2,
                "prompt": "An orange tabby crouches on a windowsill; outside is a city skyline at sunset, watercolor style, warm tones, delicate and soft, rich light and shadow layers"
            }
`

    req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonRequestBody))
    if err != nil { fmt.Println("Failed to create request:", err); return }
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil { fmt.Println("Request failed:", err); return }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    var prettyBody map[string]interface{}
    if err := json.Unmarshal(body, &prettyBody); err == nil {
        pretty, _ := json.MarshalIndent(prettyBody, "", "  ")
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(pretty))
    } else {
        fmt.Println("Status Code:", resp.StatusCode)
        fmt.Println(string(body))
    }
}

响应参数

Body 参数

参数名称 描述
background string 实际背景处理方式
created integer 生成时间戳(Unix 秒)
data array 图像数组,长度 = n
    b64_json string Base64 编码的图像数据
    generation_id string 本次生成的标识 ID
output_format string 实际输出格式
quality string 实际质量档位
size string 实际输出尺寸
usage object Token 使用统计
    input_tokens integer 输入 token 数(input_tokens_details 含 image_tokens/text_tokens 细分)
    output_tokens integer 输出 token 数(output_tokens_details 含 image_tokens 细分)
    total_tokens integer 总 token 数