Skip to content

Developers

Describe a post. Get the image back.

Send the Batkle API a post as JSON (its text, images, shapes and gradients, each where you want it) and it answers with the finished PNG. A carousel comes back with one PNG per slide.

1 credit per image. Every account starts with 100 free credits.

A real-estate post with a kitchen photo, a headline, a line of details and a yellow button, made by the API.
Made with one request. See it

Quickstart

  1. 1

    Create a key

    Sign in and open the developer dashboard. Create a key and keep it on your server, for example as BATKLE_API_KEY.

  2. 2

    Send a post

    POST the post to /api/v1/posts: its size, its background and its nodes. This one has a line of text and a short bar.

    curl https://www.batkle.com/api/v1/posts \
      -H "Authorization: Bearer $BATKLE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "width": 1080,
        "height": 1080,
        "background": "#FFD84D",
        "nodes": [
          {
            "type": "text",
            "x": 90,
            "y": 90,
            "text": "Hello from the Batkle API",
            "fontFamily": "Poppins",
            "fontSize": 112,
            "fontWeight": 800,
            "lineHeight": 1.02,
            "color": "#14131A"
          },
          {
            "type": "shape",
            "x": 90,
            "y": 860,
            "width": 160,
            "height": 12,
            "fill": "#14131A"
          }
        ]
      }' \
      --output post.png
  3. 3

    Get the image

    The answer is the PNG itself, saved here as post.png.

    A yellow square with “Hello from the Batkle API” in large black letters and a short black bar.
    The image the API returned.

Authentication

Every request carries an API key in the Authorization header. Keys start with bk_live_ and spend your account’s credits.

Header
Authorization: Bearer bk_live_…
  • Call the API from your server. A key in a browser or an app can be read by anyone who has them.
  • A key is shown once, when you create it. Batkle keeps only a fingerprint of it.
  • Revoke a key in the dashboard and it stops working at once. Use one key per place it runs, so you can revoke one alone.

The request

There is one endpoint: POST /api/v1/posts, with the post as a JSON body. A post is a size, a background and a list of nodes, the layers of the design.

widthintegerdefault 1080
The post's width in pixels, 320 to 2160.
heightintegerdefault 1350
The post's height in pixels, 320 to 2700. 1350 is Instagram's portrait post; 1080 a square one.
backgroundcolour or gradientdefault "#FFFFFF"
What fills the post behind every node.
nodesnode[]
A single post: up to 100 nodes, drawn in order.
slidesslide[]
A carousel: 2 to 10 slides, each { "background", "nodes" }. Send "nodes" or "slides", not both.
slideinteger
For a carousel: render only this slide (1 is the first) and get one PNG back.

Where nodes go

Positions and sizes are in pixels. x and y are measured from the top-left corner of the post to the top-left corner of the node. Nodes are drawn in the order of the list, so a later node covers an earlier one. A node can reach past the edges; whatever falls outside the post is cut off.

A post with a node placed x pixels from the left edge and y pixels from the top, sized by its width and height.0, 0nodexywidthheight

Nodes

There are four kinds of node, the same as the layers in the Batkle editor: text, image, shape and gradient. Every node takes these properties; the sections below list the rest. A property that isn’t listed is an error, so a typo never fails silently.

typestring
"text", "image", "shape" or "gradient". Required.
xnumberdefault 0
Distance from the left edge of the post to the node, in pixels.
ynumberdefault 0
Distance from the top edge of the post to the node, in pixels.
widthnumber
The node’s width in pixels. Required, except for text.
heightnumber
The node’s height in pixels. Required, except for text.
rotationnumberdefault 0
Degrees, clockwise, around the node’s centre.
opacitynumberdefault 1
From 0 (invisible) to 1 (solid).

Text

A box of text that wraps at its width. Without a width, text keeps the same margin on both sides of the post; without a height, its box runs to the bottom edge.

textstring or span[]
Required. Use \n for a new line. To style some words differently, send spans (below).
widthnumberdefault post width − 2 × x
Lines wrap at this width, so text keeps the same margin on both sides unless you set it.
heightnumberdefault to the bottom edge
Text that doesn’t fit in the box is cut off.
fontFamilystringdefault "Inter"
Any font from Google Fonts, by name, such as "Playfair Display" or "Poppins".
fontSizenumberdefault 48
In pixels, 6 to 600.
fontWeightintegerdefault 400
100 to 900; 700 is bold. The nearest weight the font has is used.
fontStyle"normal" | "italic"default "normal"
colorcolourdefault "#000000"
gradientgradient
Fills the letters with a gradient instead of a colour.
textAlign"left" | "center" | "right"default "left"
Where each line sits across the box.
verticalAlign"top" | "middle" | "bottom"default "top"
Where the lines sit in the box’s height.
lineHeightnumberdefault 1.2
Line spacing, as a multiple of the font size.
letterSpacingnumberdefault 0
Extra space between letters, in pixels. Can be negative.
textTransform"none" | "uppercase" | "lowercase" | "capitalize"default "none"
textDecoration"none" | "underline" | "line-through"default "none"
shadow{ x, y, blur, color }
A text shadow, in pixels: for example { "x": 0, "y": 4, "blur": 12, "color": "rgba(0,0,0,0.4)" }.

Spans: styling some words

To colour, highlight or change the font of some words, send text as an array. Plain strings take the node’s style; objects change what they set.

text
[
  "Water your plants ",
  {
    "text": "less",
    "background": "#FFD84D",
    "padding": 12
  },
  ", not more."
]
textstring
Required. The words of this span.
colorcolourdefault the node’s
backgroundcolour
A highlight behind the words.
paddingnumberdefault 0
Space between the words and the edges of the highlight, in pixels.
fontFamilystringdefault the node’s
fontSizenumberdefault the node’s
fontWeightintegerdefault the node’s
fontStyle"normal" | "italic"default the node’s
letterSpacingnumberdefault the node’s
textDecoration"none" | "underline" | "line-through"default the node’s
post.json
{
  "width": 1080,
  "height": 1080,
  "background": "#F6F3EA",
  "nodes": [
    {
      "type": "text",
      "x": 90,
      "y": 110,
      "height": 50,
      "text": "Tip of the week",
      "textTransform": "uppercase",
      "fontSize": 30,
      "fontWeight": 700,
      "letterSpacing": 6,
      "color": "#5B5766"
    },
    {
      "type": "text",
      "x": 90,
      "y": 180,
      "height": 460,
      "text": [
        "Water your plants ",
        {
          "text": "less",
          "background": "#FFD84D",
          "padding": 12
        },
        ", not more."
      ],
      "fontFamily": "Playfair Display",
      "fontSize": 104,
      "fontWeight": 700,
      "lineHeight": 1.08,
      "color": "#14131A"
    },
    {
      "type": "text",
      "x": 90,
      "y": 470,
      "height": 220,
      "text": "Most houseplants die of too much water.\nIf the top 3 cm of soil are dry, it’s time.",
      "fontSize": 38,
      "lineHeight": 1.4,
      "color": "#3B3846"
    },
    {
      "type": "text",
      "x": 90,
      "y": 940,
      "height": 60,
      "text": "@greenroom.studio",
      "fontSize": 34,
      "fontWeight": 700,
      "gradient": {
        "angle": 90,
        "stops": [
          {
            "color": "#1F7A5A"
          },
          {
            "color": "#3B5BFF"
          }
        ]
      }
    }
  ]
}
The example text post, rendered.
The image the API returned.

Image

A picture from a URL, fitted into its box. Rounded corners, masks, crops and colour filters change how it looks.

srcstring
Required. A public https URL of a PNG, JPEG, WebP, GIF or AVIF image (up to 10 MB), a data:image/…;base64 URL, or the /api/uploads/… address of an image in your Batkle account.
fit"cover" | "contain" | "fill"default "cover"
Cover fills the box and trims what overflows; contain shows the whole image inside the box; fill stretches it.
borderRadiusnumberdefault 0
Rounds the corners, in pixels.
maskstringdefault "none"
Cuts the image to a shape: "circle", "rounded", "pill", "triangle", "triangle-down", "diamond", "pentagon", "hexagon", "star", "arrow-right", "parallelogram". A masked image always covers its box.
crop{ top, right, bottom, left }
Trims a percentage off each edge of the picture. What is left keeps its place in the box.
flipXbooleandefault false
Mirrors the image left to right.
flipYbooleandefault false
Mirrors the image top to bottom.
filtersobject
Colour adjustments, each optional: brightness (0 to 300), contrast (0 to 300), saturate (0 to 300), grayscale (0 to 100), sepia (0 to 100), blur (0 to 50), hueRotate (-360 to 360). Brightness, contrast and saturate are percentages where 100 is unchanged; blur is in pixels and hueRotate in degrees.
post.json
{
  "width": 1080,
  "height": 1080,
  "background": "#1F3A5F",
  "nodes": [
    {
      "type": "image",
      "src": "https://images.unsplash.com/photo-1600585154340-be6161a56a0c?w=1200&q=80",
      "x": 90,
      "y": 90,
      "width": 900,
      "height": 600,
      "borderRadius": 36
    },
    {
      "type": "image",
      "src": "https://images.unsplash.com/photo-1494790108377-be9c29b29330?w=600&q=80",
      "x": 750,
      "y": 600,
      "width": 250,
      "height": 250,
      "mask": "circle",
      "filters": {
        "grayscale": 100,
        "contrast": 110
      }
    },
    {
      "type": "text",
      "x": 90,
      "y": 760,
      "width": 620,
      "height": 220,
      "text": "Meet Ana, the architect behind the house.",
      "fontSize": 54,
      "fontWeight": 700,
      "lineHeight": 1.12,
      "color": "#FFFFFF"
    }
  ]
}
The example image post, rendered.
The image the API returned.

Shape

A rectangle or an ellipse in one colour, with an optional outline. Thin rectangles make lines and dividers; rounded ones make buttons and pills.

shape"rectangle" | "ellipse"default "rectangle"
An ellipse with the same width and height is a circle.
fillcolourdefault "#000000"
Use "transparent" for an outline only.
borderRadiusnumberdefault 0
Rounds a rectangle’s corners, in pixels. Half the height makes a pill.
stroke{ color, width }
An outline inside the edge, such as { "color": "#14131A", "width": 4 }.
post.json
{
  "width": 1080,
  "height": 1080,
  "background": "#FFFFFF",
  "nodes": [
    {
      "type": "shape",
      "shape": "ellipse",
      "x": 620,
      "y": -160,
      "width": 600,
      "height": 600,
      "fill": "#FFD84D"
    },
    {
      "type": "text",
      "x": 90,
      "y": 130,
      "width": 600,
      "height": 340,
      "text": "Rectangles, circles, pills and lines.",
      "fontFamily": "Poppins",
      "fontSize": 76,
      "fontWeight": 700,
      "lineHeight": 1.05,
      "color": "#14131A"
    },
    {
      "type": "shape",
      "x": 90,
      "y": 560,
      "width": 900,
      "height": 6,
      "fill": "#14131A"
    },
    {
      "type": "shape",
      "x": 110,
      "y": 660,
      "width": 300,
      "height": 300,
      "fill": "#3B5BFF",
      "borderRadius": 28,
      "rotation": 10
    },
    {
      "type": "shape",
      "x": 520,
      "y": 730,
      "width": 470,
      "height": 130,
      "fill": "transparent",
      "borderRadius": 65,
      "stroke": {
        "color": "#14131A",
        "width": 6
      }
    },
    {
      "type": "text",
      "x": 520,
      "y": 730,
      "width": 470,
      "height": 130,
      "text": "A pill outline",
      "fontSize": 44,
      "fontWeight": 700,
      "color": "#14131A",
      "textAlign": "center",
      "verticalAlign": "middle"
    }
  ]
}
The example shape post, rendered.
The image the API returned.

Gradient

A rectangle or an ellipse filled with a gradient: for glows, for overlays that keep text readable on a photo, and for colour washes.

gradientgradient
Required. The colours, below.
shape"rectangle" | "ellipse"default "rectangle"
borderRadiusnumberdefault 0
Rounds a rectangle’s corners, in pixels.

The gradient object

The same object fills a gradient node, the letters of a text node (its gradient) and the post’s background.

type"linear" | "radial"default "linear"
anglenumberdefault 90
For a linear gradient, the direction in degrees: 90 runs left to right, 180 top to bottom.
center{ x, y }default { "x": 50, "y": 50 }
For a radial gradient, where it starts, in percent of the box. A radial gradient reaches position 100 at the box’s farthest corner, so a round glow that fades out before the edge ends at about 70.
stopsstop[]
Required. 2 to 10 stops, each { "color": "#RRGGBB", "position": 0 to 100, "opacity": 0 to 1 }. Positions default to even spacing and opacity to 1.
post.json
{
  "width": 1080,
  "height": 1080,
  "background": {
    "type": "linear",
    "angle": 135,
    "stops": [
      {
        "color": "#3B5BFF"
      },
      {
        "color": "#E4572E"
      }
    ]
  },
  "nodes": [
    {
      "type": "gradient",
      "x": 380,
      "y": -360,
      "width": 1060,
      "height": 1060,
      "gradient": {
        "type": "radial",
        "stops": [
          {
            "color": "#FFD84D",
            "opacity": 0.9,
            "position": 0
          },
          {
            "color": "#FFD84D",
            "opacity": 0,
            "position": 70
          }
        ]
      }
    },
    {
      "type": "gradient",
      "x": 90,
      "y": 700,
      "width": 900,
      "height": 290,
      "borderRadius": 32,
      "gradient": {
        "angle": 90,
        "stops": [
          {
            "color": "#14131A",
            "opacity": 0.85
          },
          {
            "color": "#14131A",
            "opacity": 0.35
          }
        ]
      }
    },
    {
      "type": "text",
      "x": 140,
      "y": 700,
      "width": 800,
      "height": 290,
      "text": "Gradients for backgrounds, glows and overlays.",
      "fontSize": 56,
      "fontWeight": 700,
      "lineHeight": 1.12,
      "color": "#FFFFFF",
      "verticalAlign": "middle"
    }
  ]
}
The example gradient post, rendered.
The image the API returned.

A full post

The post at the top of this page: a photo, a gradient that darkens its lower part, a headline with one coloured span, a line of details, and a button made of a shape with text on it.

post.json
{
  "width": 1080,
  "height": 1350,
  "background": "#14131A",
  "nodes": [
    {
      "type": "image",
      "src": "https://images.unsplash.com/photo-1556909114-f6e7ad7d3136?w=1200&q=80",
      "x": 0,
      "y": 0,
      "width": 1080,
      "height": 860
    },
    {
      "type": "gradient",
      "x": 0,
      "y": 460,
      "width": 1080,
      "height": 400,
      "gradient": {
        "angle": 180,
        "stops": [
          {
            "color": "#14131A",
            "opacity": 0
          },
          {
            "color": "#14131A"
          }
        ]
      }
    },
    {
      "type": "text",
      "x": 80,
      "y": 840,
      "height": 240,
      "text": [
        "Open house ",
        {
          "text": "this Saturday",
          "color": "#FFD84D"
        }
      ],
      "fontFamily": "Poppins",
      "fontSize": 92,
      "fontWeight": 700,
      "lineHeight": 1.04,
      "color": "#F6F3EA"
    },
    {
      "type": "text",
      "x": 80,
      "y": 1080,
      "height": 110,
      "text": "See the new kitchen and bathroom, from 10:00 to 16:00.",
      "fontSize": 38,
      "lineHeight": 1.35,
      "color": "#C4C1CE"
    },
    {
      "type": "shape",
      "x": 80,
      "y": 1216,
      "width": 320,
      "height": 68,
      "fill": "#FFD84D",
      "borderRadius": 34
    },
    {
      "type": "text",
      "x": 80,
      "y": 1216,
      "width": 320,
      "height": 68,
      "text": "Book a visit",
      "fontSize": 30,
      "fontWeight": 700,
      "color": "#14131A",
      "textAlign": "center",
      "verticalAlign": "middle"
    }
  ]
}
The example post post, rendered.
The image the API returned.

Save the body as post.json and send it:

curl https://www.batkle.com/api/v1/posts \
  -H "Authorization: Bearer $BATKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d @post.json \
  --output post.png

Carousels

For a carousel, send slides instead of nodes: 2 to 10 slides, each with its own nodes and, if it differs from the post’s, its own background. Every slide has the post’s size. The answer is a ZIP with one PNG per slide, named slide-01.png, slide-02.png and so on.

Slide 1 of the example carousel.Slide 2 of the example carousel.Slide 3 of the example carousel.
post.json
{
  "width": 1080,
  "height": 1350,
  "background": "#14131A",
  "slides": [
    {
      "nodes": [
        {
          "type": "image",
          "src": "https://images.unsplash.com/photo-1586023492125-27b2c045efd7?w=1200&q=80",
          "x": 0,
          "y": 0,
          "width": 1080,
          "height": 1350
        },
        {
          "type": "gradient",
          "x": 0,
          "y": 500,
          "width": 1080,
          "height": 850,
          "gradient": {
            "angle": 180,
            "stops": [
              {
                "color": "#14131A",
                "opacity": 0
              },
              {
                "color": "#14131A",
                "opacity": 0.92
              }
            ]
          }
        },
        {
          "type": "text",
          "x": 80,
          "y": 820,
          "height": 330,
          "text": "3 ways to make a small room feel bigger",
          "fontFamily": "Poppins",
          "fontSize": 88,
          "fontWeight": 700,
          "lineHeight": 1.05,
          "color": "#FFFFFF"
        },
        {
          "type": "text",
          "x": 80,
          "y": 1190,
          "height": 60,
          "text": "Swipe for the first one",
          "fontSize": 34,
          "fontWeight": 700,
          "color": "#FFD84D"
        }
      ]
    },
    {
      "background": "#F6F3EA",
      "nodes": [
        {
          "type": "text",
          "x": 80,
          "y": 110,
          "height": 140,
          "text": "01",
          "fontFamily": "Poppins",
          "fontSize": 120,
          "fontWeight": 700,
          "color": "#F2A900"
        },
        {
          "type": "text",
          "x": 80,
          "y": 300,
          "height": 260,
          "text": "Paint the ceiling lighter than the walls",
          "fontFamily": "Poppins",
          "fontSize": 72,
          "fontWeight": 700,
          "lineHeight": 1.08,
          "color": "#14131A"
        },
        {
          "type": "text",
          "x": 80,
          "y": 520,
          "height": 400,
          "text": "A light ceiling reflects more light and reads as higher. Matte white works in almost any room.",
          "fontSize": 40,
          "lineHeight": 1.45,
          "color": "#3B3846"
        },
        {
          "type": "shape",
          "x": 80,
          "y": 1200,
          "width": 920,
          "height": 4,
          "fill": "#14131A",
          "opacity": 0.15
        }
      ]
    },
    {
      "background": "#FFD84D",
      "nodes": [
        {
          "type": "text",
          "x": 80,
          "y": 80,
          "height": 1190,
          "text": "Want the other two? Save this post.",
          "fontFamily": "Poppins",
          "fontSize": 96,
          "fontWeight": 700,
          "lineHeight": 1.05,
          "color": "#14131A",
          "verticalAlign": "middle"
        }
      ]
    }
  ]
}
curl https://www.batkle.com/api/v1/posts \
  -H "Authorization: Bearer $BATKLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d @post.json \
  --output carousel.zip

To get one slide as a PNG, add "slide": 2 to the body. Only that slide is rendered, for one credit: handy to preview a slide, or to fetch slides one at a time.

The response

A successful request answers 200 with the image in the body: image/png for a single post or one slide, application/zip for a carousel. Batkle keeps no copy, so save it. These headers come with it:

X-Credits-Chargedinteger
Credits this request cost.
X-Credits-Remaininginteger
Your balance after it.
X-Imagesinteger
How many images it rendered.
X-Request-Idstring
Quote it when you contact us about a request.

An error answers with JSON instead; see Errors. Most posts take one to three seconds a slide, a little longer the first time a font or image is used.

Fonts and colours

fontFamily takes the name of any font on Google Fonts, as it is written there: "Poppins", "Playfair Display", "Bebas Neue". Batkle loads the weight you ask for, or the nearest one the font has. A name it can’t find falls back to Inter. System fonts such as Arial and Helvetica aren’t available.

Fonts are loaded with their Latin characters, which covers English and the other Western European languages, accents included (ã, é, ç, ß). Emoji, arrows such as →, and other scripts such as Greek, Cyrillic or Arabic are not drawn yet.

Colours are hex ("#F2A900", "#F2A90080" with transparency), rgb() and rgba(), hsl() and hsla(), or a CSS name such as "white" or "transparent". Gradient stops take hex colours only.

From the editor

The quickest way to a good layout is to design it in Batkle. Open any post in the editor, go to the API tab and copy it as a request: you get this same JSON for the design, with every node in place. Change its texts and image URLs from your code, and send it.

Credits

Each image costs 1 credit: a single post is one, a carousel one per slide. Credits are taken when rendering starts and given back if it fails. When the balance is too low, the request fails with 402 insufficient_credits and nothing is rendered. New accounts start with 100 free credits. The dashboard shows your balance and what each key used.

Errors

Errors use HTTP status codes and a JSON body with a stable type for your code and a message for people. Messages about the body name the property at fault.

Response 400
{
  "error": {
    "type": "invalid_request",
    "message": "\"nodes[1].fontsize\" is not a property here. Did you mean \"fontSize\"?",
    "request_id": "req_4f0c2a9e1b7d4c3a8e6f5d21"
  }
}
400
invalid_request
The body is not valid; the message names the property, such as "nodes[2].fontSize" must be from 6 to 600.
401
authentication_error
The key is missing, not valid, or revoked.
402
insufficient_credits
The balance is too low. The error says how many credits were needed and what is left.
404
not_found
There is no such endpoint.
405
invalid_request
/v1/posts takes POST.
413
invalid_request
The body is larger than 4 MB. Send big images as URLs instead of data URLs.
422
image_unavailable
An image could not be loaded: the message names it and says why.
429
rate_limited
More than 60 requests a minute on one key. Wait the seconds in the Retry-After header.
500
server_error
Something failed on our side. Nothing was charged; try again.

Limits

Post size
320 to 2160 px wide, 320 to 2700 px high
Nodes
100 per post or slide
Slides
2 to 10 per carousel
Images
40 different images per request, 10 MB each
Request body
4 MB
Requests
60 a minute per key
Cost
1 credit per image

Over 60 requests a minute, the API answers 429 with a Retry-After header: wait that many seconds, then try again.

Render your first post in a minute.

Create a key, send a few nodes, and get the image back.

Get an API key