Formato ufficiale
Creare un'immagine Runway
Usa POST /runwayml/v1/text_to_image per avviare un task Runway che genera immagini da un prompt testuale, con supporto 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"
}Usa questo endpoint per creare un task Runway di generazione di immagini.
Note sull’utilizzo
- Invia l’header richiesto
X-Runway-Version, ad esempio2024-11-06 - Usa
model: gen4_image - Questa route richiede almeno un elemento
referenceImages— una richiesta solo testuale restituiscereference_images_empty
Flusso del task
1
Invia la richiesta di generazione
Invia
promptText, ratio, model e almeno un oggetto referenceImages.2
Memorizza l'id restituito
Conserva l’
id restituito, perché questa route è asincrona.3
Interroga il task
Usa Ottenere un task Runway. Se un’interrogazione immediata restituisce
task_not_exist, attendi qualche secondo e riprova.Autorizzazioni
Bearer token authentication. Use your CometAPI key.
Intestazioni
Runway version header, for example 2024-11-06.
Corpo
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
Risposta
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"
}