Skip to main content

Response format and strcuture

You can get back the generated image through Pika API in two formats:

  • binary: Sends back image binary as response
  • base64: Sends back generated image's base64
  • url: Sends back direct link to image hosted by Pika

You can set the response format while making requests like so:

const response = await fetch(`${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: {
}).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: ""

For binary, you get the image in binary format