Dynamic OG Images with FastAPI

Add OG image generation to any FastAPI route with Python's standard urllib. Works with Jinja2 templates.

Start Integrating

Async Ready

Full async/await support. Integrate seamlessly with your async database queries.

Type Safe

Works with Pydantic models for automatic serialization and validation.

Jinja2 Native

Pass the OG URL to your Jinja2 templates. Works with FastAPI's TemplateResponse.

Example Integration

from fastapi import FastAPI, Request
from fastapi.templating import Jinja2Templates
from urllib.parse import urlencode
import os

app = FastAPI()
templates = Jinja2Templates(directory="templates")

@app.get("/blog/{slug}")
async def blog_post(slug: str, request: Request):
    post = await get_post(slug)
    og_url = "https://imagoapi.com/api/og/generate?" + urlencode({
        "title":    post.title,
        "template": "modern",
        "api_key":  os.environ["IMAGO_API_KEY"],
    })
    return templates.TemplateResponse("post.html", {
        "request": request,
        "post": post,
        "og_url": og_url
    })
# post.html: <meta property="og:image" content="{{ og_url }}">

Generate OG Images in Seconds

Start using Imago API today and add beautiful social cards to your FastAPI app.

Try Imago API Free