Skip to Content
Create Image from HTML

Create Image from HTML

Send a POST request to this endpoint to create a new image using custom HTML.

You will need to authenticate to use this API. See authentication.

This endpoint consumes 1 credit per image. The credit is spent when the render starts, and a render that fails costs nothing: its credit is refunded.

Request

POST https://api.ojo.so/v1/image/html

Headers

HeaderValueDescription
Content-Typetext/htmlSpecify that the request body contains HTML
x-viewport-widthnumber(Optional) Width of the viewport in pixels (default: 1280)
x-viewport-heightnumber(Optional) Height of the viewport in pixels (default: 800)
x-transparent-backgroundboolean(Optional) When set to true, generates the image with a transparent background. Defaults to false if not specified.

Request Body

The request body should contain the HTML content you want to render as an image.

You can also send JSON with Content-Type: application/json. A value in the body wins over its header.

FieldTypeDescription
htmlstringThe HTML to render
viewportWidthnumber(Optional) Width of the viewport in pixels (default: 1280)
viewportHeightnumber(Optional) Height of the viewport in pixels (default: 800)
transparentBackgroundboolean(Optional) When true, renders without a background colour
curl --request POST \ --url https://api.ojo.so/v1/image/html \ --header 'Authorization: Bearer <your API key>' \ --header 'Content-Type: text/html' \ --header 'x-viewport-width: 1500' \ --header 'x-viewport-height: 1000' \ --data '<html><body><div id="main-content"><h1>Hello, World!</h1></div></body></html>'

Response

Everything went as planned and your image is generated.

{ "id": "image-id", "imageUrl": "https://example.com/path/to/image.png", "createdAt": "2023-08-29T12:34:56Z" }