Code2Img

Your code, over HTTP.

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.

Base URL and authentication

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.

Endpoints

Render a card

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.

Quotas

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.

Three ways in

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.