Format officiel
Créer une image Runway
Utilisez POST /runwayml/v1/text_to_image pour démarrer une tâche Runway qui génère des images à partir d’un prompt textuel, avec la prise en charge de 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"
}Utilisez ce point de terminaison pour créer une tâche de génération d’image Runway.
Notes d’utilisation
- Envoyez l’en-tête requis
X-Runway-Version, par exemple2024-11-06 - Utilisez
model: gen4_image - Cette route nécessite au moins un élément
referenceImages— une requête contenant uniquement du texte renvoiereference_images_empty
Flux de la tâche
1
Soumettre la requête de génération
Envoyez
promptText, ratio, model et au moins un objet referenceImages.2
Stocker l’id retourné
Conservez l’
id retourné, car cette route est asynchrone.3
Interroger la tâche
Utilisez Obtenir une tâche Runway. Si une interrogation immédiate renvoie
task_not_exist, attendez quelques secondes puis réessayez.Autorisations
Bearer token authentication. Use your CometAPI key.
En-têtes
Runway version header, for example 2024-11-06.
Corps
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
Réponse
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"
}