curl --request POST \
--url https://api.powertokens.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "image-01",
"prompt": "A cinematic sunrise over a calm harbor",
"aspect_ratio": "16:9",
"response_format": "base64",
"seed": 0,
"n": 1,
"prompt_optimizer": false
}
'import requests
url = "https://api.powertokens.ai/v1/images/generations"
payload = {
"model": "image-01",
"prompt": "A cinematic sunrise over a calm harbor",
"aspect_ratio": "16:9",
"response_format": "base64",
"seed": 0,
"n": 1,
"prompt_optimizer": False
}
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({
model: 'image-01',
prompt: 'A cinematic sunrise over a calm harbor',
aspect_ratio: '16:9',
response_format: 'base64',
seed: 0,
n: 1,
prompt_optimizer: false
})
};
fetch('https://api.powertokens.ai/v1/images/generations', 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.powertokens.ai/v1/images/generations",
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([
'model' => 'image-01',
'prompt' => 'A cinematic sunrise over a calm harbor',
'aspect_ratio' => '16:9',
'response_format' => 'base64',
'seed' => 0,
'n' => 1,
'prompt_optimizer' => false
]),
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.powertokens.ai/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\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.powertokens.ai/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.powertokens.ai/v1/images/generations")
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 \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>",
"b64_json": "<string>"
}
],
"metadata": {
"provider_request_id": "<string>",
"provider_status_code": 123,
"provider_status_msg": "<string>",
"success_count": 123,
"failed_count": 123
}
}{
"error": {
"message": "Malformed request body or invalid field values",
"type": "invalid_request_error",
"code": "bad_request_body"
}
}{
"error": {
"message": "Invalid token",
"type": "api_error",
"code": "access_denied"
}
}{
"error": {
"message": "Request body too large, please reduce the input and retry",
"type": "api_error",
"code": "read_request_body_failed"
}
}{
"error": {
"message": "Insufficient account quota, please retry later",
"type": "api_error",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Internal processing failed, please retry later",
"type": "api_error",
"code": "gen_relay_info_failed"
}
}{
"error": {
"message": "The upstream provider returned an invalid response",
"type": "api_error",
"code": "bad_response_status_code"
}
}{
"error": {
"message": "No available channel for the current model, please retry later",
"type": "api_error",
"code": "get_channel_failed"
}
}Image-01 Text to Image
Text-to-image capability for the image-01 model.
Exposed fields: model, prompt, aspect_ratio, width, height, response_format, seed, n, prompt_optimizer.
curl --request POST \
--url https://api.powertokens.ai/v1/images/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "image-01",
"prompt": "A cinematic sunrise over a calm harbor",
"aspect_ratio": "16:9",
"response_format": "base64",
"seed": 0,
"n": 1,
"prompt_optimizer": false
}
'import requests
url = "https://api.powertokens.ai/v1/images/generations"
payload = {
"model": "image-01",
"prompt": "A cinematic sunrise over a calm harbor",
"aspect_ratio": "16:9",
"response_format": "base64",
"seed": 0,
"n": 1,
"prompt_optimizer": False
}
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({
model: 'image-01',
prompt: 'A cinematic sunrise over a calm harbor',
aspect_ratio: '16:9',
response_format: 'base64',
seed: 0,
n: 1,
prompt_optimizer: false
})
};
fetch('https://api.powertokens.ai/v1/images/generations', 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.powertokens.ai/v1/images/generations",
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([
'model' => 'image-01',
'prompt' => 'A cinematic sunrise over a calm harbor',
'aspect_ratio' => '16:9',
'response_format' => 'base64',
'seed' => 0,
'n' => 1,
'prompt_optimizer' => false
]),
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.powertokens.ai/v1/images/generations"
payload := strings.NewReader("{\n \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\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.powertokens.ai/v1/images/generations")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.powertokens.ai/v1/images/generations")
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 \"model\": \"image-01\",\n \"prompt\": \"A cinematic sunrise over a calm harbor\",\n \"aspect_ratio\": \"16:9\",\n \"response_format\": \"base64\",\n \"seed\": 0,\n \"n\": 1,\n \"prompt_optimizer\": false\n}"
response = http.request(request)
puts response.read_body{
"created": 123,
"data": [
{
"url": "<string>",
"b64_json": "<string>"
}
],
"metadata": {
"provider_request_id": "<string>",
"provider_status_code": 123,
"provider_status_msg": "<string>",
"success_count": 123,
"failed_count": 123
}
}{
"error": {
"message": "Malformed request body or invalid field values",
"type": "invalid_request_error",
"code": "bad_request_body"
}
}{
"error": {
"message": "Invalid token",
"type": "api_error",
"code": "access_denied"
}
}{
"error": {
"message": "Request body too large, please reduce the input and retry",
"type": "api_error",
"code": "read_request_body_failed"
}
}{
"error": {
"message": "Insufficient account quota, please retry later",
"type": "api_error",
"code": "insufficient_user_quota"
}
}{
"error": {
"message": "Internal processing failed, please retry later",
"type": "api_error",
"code": "gen_relay_info_failed"
}
}{
"error": {
"message": "The upstream provider returned an invalid response",
"type": "api_error",
"code": "bad_response_status_code"
}
}{
"error": {
"message": "No available channel for the current model, please retry later",
"type": "api_error",
"code": "get_channel_failed"
}
}Authorizations
Pass Authorization: Bearer <token> in the request header.
Body
Model name for this capability.
image-01 Image generation prompt.
1500Target aspect ratio.
1:1, 16:9, 4:3, 3:2, 2:3, 3:4, 9:16, 21:9 Generated image width (pixels). Only effective when model is image-01. Note: width and height must be set together, range [512, 2048], and must be multiples of 8. If set together with aspect_ratio, aspect_ratio takes priority.
512 <= x <= 2048Must be a multiple of 8Generated image height (pixels). Only effective when model is image-01. Note: width and height must be set together, range [512, 2048], and must be multiples of 8. If set together with aspect_ratio, aspect_ratio takes priority.
512 <= x <= 2048Must be a multiple of 8Response format. Use url to get a temporary download link, or base64 to get Base64-encoded content.
url, base64 Random seed. Explicitly passing 0 will be preserved.
Number of images to generate.
1 <= x <= 9Whether to enable prompt optimization. Explicitly passing false will be preserved.