Code2Img's REST API turns a JSON config into a code image: PNG, JPG or PDF at up to 4×. Keys, scopes, quotas, signed URLs, the OpenAPI spec and the TypeScript SDK.
The editor, the API and the MCP server all call the same render service. Whatever you can build in the editor, you can ask for over HTTP: a code image from a JSON config, with the same themes, the same limits and the same bytes.
Every endpoint lives under https://code2img.app/api/v1 and takes a key in the Authorization header:
Authorization: Bearer c2i_sk_…
Create keys in the dashboard. A key carries scopes (read, write, upload) and is stored hashed, with a readable prefix so you can tell two keys apart. Rotation and revocation are immediate; requests are idempotent when you send an Idempotency-Key. Errors come back as RFC 9457 problem documents with a stable type, so a client can branch on the error rather than on prose.
POST /images — render a card. Send a config (code, language, theme, font, title, background, scale) plus format (png, jpg, pdf) and scale up to 4×. Default response is the image bytes; response_type: "url" stores it and returns { id, url, expires_at }.POST /share — create a public page for a snippet and get back its slug, URL and expiry.POST /signed-url — sign a render URL, so a browser or an <img> tag can fetch it without carrying your key.POST /uploads — upload a background image or a logo (Pro).GET /usage — the calls left in the current minute and day, per key.GET /themes, /languages, /fonts, /backgrounds — the catalogs, public, no key needed.GET /openapi.json — the OpenAPI 3.1 specification for all of the above.curl -X POST https://code2img.app/api/v1/images \
-H "Authorization: Bearer $CODE2IMG_API_KEY" \
-H "content-type: application/json" \
-d '{"config":{"code":"print(\"hi\")","language":"python","theme":"tokyo-night"},"format":"png","scale":2}' \
--output card.png
Drop language and the service guesses from the snippet with the same ordered rules the editor uses.
Free keys get 30 requests a minute and 500 a day; Pro keys get 300 a minute and 5.000 a day. Both limits are enforced in Redis, per key and per IP, and the response headers tell you where you stand — X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset. Exceeding a limit returns 429 with Retry-After; a burst of identical retries is absorbed by the idempotency key, not billed twice.
Paste in the editor when you want to see it. Call the API from a build script, a CI job or a docs generator. Or let an agent do it: the MCP server exposes render_code_image, list_themes, list_languages, list_backgrounds, create_share_link, get_share_urls and get_usage to any MCP client, over the same API and the same quotas.
The interactive reference — every endpoint, every field, try-it-out — is at /docs.