Flux Kontext 图片生成/编辑
curl --request POST \
--url https://api.sinancode.com/v1/generate/k/flux-kontext \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "a beautiful landscape with mountains",
"aspect_ratio": "16:9",
"enable_translation": true,
"input_image": "https://example.com/input.jpg",
"model": "flux-kontext-pro",
"output_format": "jpeg",
"prompt_upsampling": false,
"safety_tolerance": 2,
"upload_cn": false,
"watermark": ""
}
'import requests
url = "https://api.sinancode.com/v1/generate/k/flux-kontext"
payload = {
"prompt": "a beautiful landscape with mountains",
"aspect_ratio": "16:9",
"enable_translation": True,
"input_image": "https://example.com/input.jpg",
"model": "flux-kontext-pro",
"output_format": "jpeg",
"prompt_upsampling": False,
"safety_tolerance": 2,
"upload_cn": False,
"watermark": ""
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'a beautiful landscape with mountains',
aspect_ratio: '16:9',
enable_translation: true,
input_image: 'https://example.com/input.jpg',
model: 'flux-kontext-pro',
output_format: 'jpeg',
prompt_upsampling: false,
safety_tolerance: 2,
upload_cn: false,
watermark: ''
})
};
fetch('https://api.sinancode.com/v1/generate/k/flux-kontext', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sinancode.com/v1/generate/k/flux-kontext",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'a beautiful landscape with mountains',
'aspect_ratio' => '16:9',
'enable_translation' => true,
'input_image' => 'https://example.com/input.jpg',
'model' => 'flux-kontext-pro',
'output_format' => 'jpeg',
'prompt_upsampling' => false,
'safety_tolerance' => 2,
'upload_cn' => false,
'watermark' => ''
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sinancode.com/v1/generate/k/flux-kontext"
payload := strings.NewReader("{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sinancode.com/v1/generate/k/flux-kontext")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sinancode.com/v1/generate/k/flux-kontext")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}"
response = http.request(request)
puts response.read_body{
"task_id": "01234567-89ab-cdef-0123-456789abcdef"
}{
"error_code": "<string>",
"message": "<string>"
}{
"error_code": "<string>",
"message": "<string>"
}{
"error_code": "<string>",
"message": "<string>"
}图片生成 - Flux
Flux Kontext
使用 Flux Kontext 模型生成或编辑图片(异步)
POST
/
generate
/
k
/
flux-kontext
Flux Kontext 图片生成/编辑
curl --request POST \
--url https://api.sinancode.com/v1/generate/k/flux-kontext \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"prompt": "a beautiful landscape with mountains",
"aspect_ratio": "16:9",
"enable_translation": true,
"input_image": "https://example.com/input.jpg",
"model": "flux-kontext-pro",
"output_format": "jpeg",
"prompt_upsampling": false,
"safety_tolerance": 2,
"upload_cn": false,
"watermark": ""
}
'import requests
url = "https://api.sinancode.com/v1/generate/k/flux-kontext"
payload = {
"prompt": "a beautiful landscape with mountains",
"aspect_ratio": "16:9",
"enable_translation": True,
"input_image": "https://example.com/input.jpg",
"model": "flux-kontext-pro",
"output_format": "jpeg",
"prompt_upsampling": False,
"safety_tolerance": 2,
"upload_cn": False,
"watermark": ""
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
prompt: 'a beautiful landscape with mountains',
aspect_ratio: '16:9',
enable_translation: true,
input_image: 'https://example.com/input.jpg',
model: 'flux-kontext-pro',
output_format: 'jpeg',
prompt_upsampling: false,
safety_tolerance: 2,
upload_cn: false,
watermark: ''
})
};
fetch('https://api.sinancode.com/v1/generate/k/flux-kontext', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sinancode.com/v1/generate/k/flux-kontext",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'a beautiful landscape with mountains',
'aspect_ratio' => '16:9',
'enable_translation' => true,
'input_image' => 'https://example.com/input.jpg',
'model' => 'flux-kontext-pro',
'output_format' => 'jpeg',
'prompt_upsampling' => false,
'safety_tolerance' => 2,
'upload_cn' => false,
'watermark' => ''
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sinancode.com/v1/generate/k/flux-kontext"
payload := strings.NewReader("{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sinancode.com/v1/generate/k/flux-kontext")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sinancode.com/v1/generate/k/flux-kontext")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"prompt\": \"a beautiful landscape with mountains\",\n \"aspect_ratio\": \"16:9\",\n \"enable_translation\": true,\n \"input_image\": \"https://example.com/input.jpg\",\n \"model\": \"flux-kontext-pro\",\n \"output_format\": \"jpeg\",\n \"prompt_upsampling\": false,\n \"safety_tolerance\": 2,\n \"upload_cn\": false,\n \"watermark\": \"\"\n}"
response = http.request(request)
puts response.read_body{
"task_id": "01234567-89ab-cdef-0123-456789abcdef"
}{
"error_code": "<string>",
"message": "<string>"
}{
"error_code": "<string>",
"message": "<string>"
}{
"error_code": "<string>",
"message": "<string>"
}使用 Black Forest Labs 的 FLUX.1 Kontext 模型进行上下文感知的图像生成与编辑。
模型特点:
- 上下文理解 - 通过文本指令直接修改现有图像,无需复杂工作流
- 角色一致性 - 跨多场景保持人物/物体的视觉特征一致
- 局部编辑 - 精准修改图像特定区域,不影响其他部分
- 快速迭代 - 3-5 秒生成 1MP 图像,比 GPT-Image 快 8 倍
授权
请使用您的 API Token 进行认证
请求体
application/json
任务参数
提示词(必填,支持英文)
Minimum string length:
1示例:
"a beautiful landscape with mountains"
宽高比(可选,默认 16:9)
可用选项:
auto, 21:9, 16:9, 4:3, 1:1, 3:4, 9:16 示例:
"16:9"
启用自动翻译(可选,默认 true)
示例:
true
输入图片 URL(可选,编辑模式使用)
示例:
"https://example.com/input.jpg"
模型版本(可选,默认 flux-kontext-pro)
可用选项:
flux-kontext-pro, flux-kontext-max 示例:
"flux-kontext-pro"
输出格式(可选,默认 jpeg)
可用选项:
jpeg, png 示例:
"jpeg"
启用提示词增强(可选,默认 false)
示例:
false
安全容忍等级(可选,0-6,默认2)
必填范围:
0 <= x <= 6示例:
2
使用中国大陆服务器上传(可选)
示例:
false
水印标识(可选)
示例:
""
响应
OK
Task ID
示例:
"01234567-89ab-cdef-0123-456789abcdef"
⌘I