Skip to content

cURL Examples

Command-line examples using cURL.

Basic Generation

Generate a simple image:

bash
curl -X POST https://ogimageapi.io/api/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: og_your_api_key" \
  -d '{"title": "Hello World"}' \
  --output image.png

With All Options

Full example with all parameters:

bash
curl -X POST https://ogimageapi.io/api/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: og_your_api_key" \
  -d '{
    "title": "The Complete Guide to Building APIs",
    "subtitle": "Learn best practices for designing and implementing RESTful services",
    "author_name": "Jane Developer",
    "author_avatar_url": "https://avatars.githubusercontent.com/u/12345",
    "theme": "dark",
    "template": "default"
  }' \
  --output blog-post.png

Light Theme

bash
curl -X POST https://ogimageapi.io/api/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: og_your_api_key" \
  -d '{
    "title": "Product Launch",
    "subtitle": "Introducing our newest feature",
    "theme": "light",
    "template": "minimal"
  }' \
  --output launch.png

Check Usage

bash
curl https://ogimageapi.io/api/user/usage \
  -H "X-API-Key: og_your_api_key"

Using Environment Variables

Store your API key safely:

bash
# Set once
export OG_API_KEY="og_your_api_key"

# Use in requests
curl -X POST https://ogimageapi.io/api/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $OG_API_KEY" \
  -d '{"title": "Using Environment Variables"}' \
  --output image.png

Batch Script

Generate multiple images:

bash
#!/bin/bash

API_KEY="og_your_api_key"
API_URL="https://ogimageapi.io/api/generate"

# Array of posts
posts=(
  '{"title": "First Post", "subtitle": "Introduction"}'
  '{"title": "Second Post", "subtitle": "Getting Started"}'
  '{"title": "Third Post", "subtitle": "Advanced Topics"}'
)

# Generate images
for i in "${!posts[@]}"; do
  curl -X POST "$API_URL" \
    -H "Content-Type: application/json" \
    -H "X-API-Key: $API_KEY" \
    -d "${posts[$i]}" \
    --output "image-$i.png"
  
  echo "Generated image-$i.png"
done

Error Handling

Check for errors:

bash
response=$(curl -s -w "\n%{http_code}" -X POST https://ogimageapi.io/api/generate \
  -H "Content-Type: application/json" \
  -H "X-API-Key: og_your_api_key" \
  -d '{"title": "Test"}' \
  --output image.png)

http_code=$(echo "$response" | tail -n1)

if [ "$http_code" -ne 200 ]; then
  echo "Error: HTTP $http_code"
  cat image.png  # Will contain error JSON
else
  echo "Success!"
fi

Generate stunning Open Graph images programmatically.