Response format and strcuture
You can get back the generated image through Pika API in two formats:
binary
: Sends back image binary as responsebase64
: Sends back generated image's base64url
: Sends back direct link to image hosted by Pika
You can set the response format while making requests like so:
const response = await fetch(`https://api.pika.style/v1/templates/${PIKA_TEMPLATE_ID}/images`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${PIKA_API_KEY}`,
},
body: JSON.stringify({
response_format: "base64", // Optional, default is base64, can be "base64" or "binary"
modifications: {
YOUR_MODIFICATIONS
},
}),
}).then((res) => res.json());
By default if you don't specify a response_format
, you'll get the image back in base64 format
Response structure
The response looks like this:
For base64
response format:
{
data: {
base64: "data:image/png;base64,iVBORw0KGgoA..."
}
}
For url
response format:
{
data: {
url: "https://assets.pika.style/3dss4s-234sd2-2e12/image.png"
}
}
For binary
, you get the image in binary format