官方格式
建立 Runway 圖像
使用 POST /runwayml/v1/text_to_image 啟動會根據文字 Prompt 產生圖像的 Runway 任務,並支援 X-Runway-Version。
POST
/
runwayml
/
v1
/
text_to_image
cURL
curl https://api.cometapi.com/runwayml/v1/text_to_image \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/runwayml/v1/text_to_image",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
},
)
task = response.json()
print(task["id"]) # poll GET /runwayml/v1/tasks/{id} until the output array appearsconst response = await fetch("https://api.cometapi.com/runwayml/v1/text_to_image", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
}),
});
const task = await response.json();
console.log(task.id); // poll GET /runwayml/v1/tasks/{id} until the output array appears<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/runwayml/v1/text_to_image",
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([
'promptText' => 'A paper boat floating on calm water at sunrise.',
'ratio' => '1280:720',
'seed' => 1,
'model' => 'gen4_image',
'referenceImages' => [
[
'uri' => 'https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg',
'tag' => 'style_ref'
]
],
'contentModeration' => [
'publicFigureThreshold' => 'auto'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Runway-Version: <x-runway-version>"
],
]);
$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.cometapi.com/runwayml/v1/text_to_image"
payload := strings.NewReader("{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Runway-Version", "<x-runway-version>")
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.cometapi.com/runwayml/v1/text_to_image")
.header("X-Runway-Version", "<x-runway-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/runwayml/v1/text_to_image")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Runway-Version"] = '<x-runway-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "31f9c5b2-ea5c-421c-8044-75a6bb53211d"
}使用此端點建立 Runway 圖像生成任務。
使用說明
- 傳送必要的
X-Runway-Version標頭,例如2024-11-06 - 使用
model: gen4_image - 此路由至少需要一個
referenceImages項目——僅文字請求會回傳reference_images_empty
任務流程
1
提交生成請求
傳送
promptText、ratio、model,以及至少一個 referenceImages 物件。2
儲存回傳的 id
保留回傳的
id,因為此路由是非同步的。3
輪詢任務
使用 取得 Runway 任務。如果立即輪詢回傳
task_not_exist,請等待幾秒後重試。授權
Bearer token authentication. Use your CometAPI key.
標頭
Runway version header, for example 2024-11-06.
主體
application/json
A non-empty string up to 1000 characters.
Aspect ratio of the output image, e.g. 1280:720.
Random seed for reproducible results.
The model variant to use.
An array of up to three images to be used as references. At least one item is required. referenceImages is required.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
回應
200 - application/json
Task accepted.
⌘I
cURL
curl https://api.cometapi.com/runwayml/v1/text_to_image \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
}'import os
import requests
response = requests.post(
"https://api.cometapi.com/runwayml/v1/text_to_image",
headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
json={
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
},
)
task = response.json()
print(task["id"]) # poll GET /runwayml/v1/tasks/{id} until the output array appearsconst response = await fetch("https://api.cometapi.com/runwayml/v1/text_to_image", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
"promptText": "A paper boat floating on calm water at sunrise.",
"ratio": "1280:720",
"model": "gen4_image",
"referenceImages": [
{
"uri": "https://your-image-host/reference.jpg",
"tag": "ref"
}
]
}),
});
const task = await response.json();
console.log(task.id); // poll GET /runwayml/v1/tasks/{id} until the output array appears<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.cometapi.com/runwayml/v1/text_to_image",
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([
'promptText' => 'A paper boat floating on calm water at sunrise.',
'ratio' => '1280:720',
'seed' => 1,
'model' => 'gen4_image',
'referenceImages' => [
[
'uri' => 'https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg',
'tag' => 'style_ref'
]
],
'contentModeration' => [
'publicFigureThreshold' => 'auto'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"X-Runway-Version: <x-runway-version>"
],
]);
$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.cometapi.com/runwayml/v1/text_to_image"
payload := strings.NewReader("{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("X-Runway-Version", "<x-runway-version>")
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.cometapi.com/runwayml/v1/text_to_image")
.header("X-Runway-Version", "<x-runway-version>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.cometapi.com/runwayml/v1/text_to_image")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["X-Runway-Version"] = '<x-runway-version>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"promptText\": \"A paper boat floating on calm water at sunrise.\",\n \"ratio\": \"1280:720\",\n \"seed\": 1,\n \"model\": \"gen4_image\",\n \"referenceImages\": [\n {\n \"uri\": \"https://cdn.britannica.com/70/234870-050-D4D024BB/Orange-colored-cat-yawns-displaying-teeth.jpg\",\n \"tag\": \"style_ref\"\n }\n ],\n \"contentModeration\": {\n \"publicFigureThreshold\": \"auto\"\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "31f9c5b2-ea5c-421c-8044-75a6bb53211d"
}