{
  "openapi": "3.1.0",
  "info": {
    "title": "Code to Image API",
    "version": "1.0.0",
    "description": "Render code snippets as beautiful PNG/SVG images. Also available: the web editor at https://codetoimage.com (share links use /#s=BLOB), an MCP server at https://codetoimage.com/mcp (streamable HTTP), and an agent skill via `npx skills add https://codetoimage.com`. Do not send private or sensitive source code without authorization."
  },
  "servers": [
    {
      "url": "https://codetoimage.com"
    }
  ],
  "paths": {
    "/api/image": {
      "get": {
        "summary": "Render a code image from query parameters",
        "description": "Pass either `s` (the base64url state blob from a share link — swap \"/#s=\" for \"/api/image?s=\" on any share URL) or individual state fields as query parameters. Responses are long-cacheable.",
        "parameters": [
          {
            "name": "s",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "base64url-encoded JSON state from a share link. When present, other state params are ignored."
          },
          {
            "name": "code",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 20000,
              "description": "The source code to render. Required."
            }
          },
          {
            "name": "language",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "javascript",
                "typescript",
                "tsx",
                "jsx",
                "python",
                "java",
                "cpp",
                "c",
                "csharp",
                "php",
                "ruby",
                "go",
                "rust",
                "swift",
                "kotlin",
                "dart",
                "html",
                "css",
                "scss",
                "json",
                "yaml",
                "xml",
                "sql",
                "bash",
                "powershell",
                "markdown",
                "vue",
                "svelte",
                "graphql",
                "dockerfile",
                "toml",
                "lua",
                "r",
                "scala",
                "elixir",
                "haskell",
                "zig"
              ],
              "default": "javascript"
            }
          },
          {
            "name": "theme",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "github-dark",
                "dracula",
                "one-dark-pro",
                "nord",
                "tokyo-night",
                "catppuccin-mocha",
                "catppuccin-macchiato",
                "vesper",
                "vitesse-dark",
                "ayu-dark",
                "houston",
                "synthwave-84",
                "night-owl",
                "poimandres",
                "andromeeda",
                "material-theme-darker",
                "material-theme-ocean",
                "material-theme-palenight",
                "slack-dark",
                "aurora-x",
                "rose-pine",
                "rose-pine-moon",
                "monokai",
                "solarized-dark",
                "min-dark",
                "everforest-dark",
                "gruvbox-dark-hard",
                "kanagawa-dragon",
                "github-light",
                "catppuccin-latte",
                "vitesse-light",
                "rose-pine-dawn",
                "min-light",
                "solarized-light",
                "everforest-light",
                "slack-ochin",
                "one-light",
                "snazzy-light"
              ],
              "default": "github-dark"
            }
          },
          {
            "name": "fontFamily",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "jetbrains-mono",
                "fira-code",
                "geist-mono",
                "source-code-pro",
                "cascadia-code",
                "ibm-plex-mono",
                "monaspace-neon"
              ],
              "default": "jetbrains-mono",
              "description": "Hosted renders always use JetBrains Mono; other values apply in the web editor via share links."
            }
          },
          {
            "name": "fontSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 10,
              "maximum": 28,
              "default": 14
            }
          },
          {
            "name": "lineNumbers",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "lineNumberStart",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "tabSize",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 8,
              "default": 2
            }
          },
          {
            "name": "padding",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 256,
              "default": 64,
              "description": "Space around the code window, in px."
            }
          },
          {
            "name": "borderRadius",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 48,
              "default": 16
            }
          },
          {
            "name": "backgroundVisible",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          },
          {
            "name": "backgroundOpacity",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100,
              "default": 100
            }
          },
          {
            "name": "backgroundColor",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^#[0-9a-fA-F]{3,8}$",
              "default": "#6B5CE7",
              "description": "Solid background. Used when backgroundGradient is null."
            }
          },
          {
            "name": "backgroundGradient",
            "in": "query",
            "schema": {
              "type": [
                "string",
                "null"
              ],
              "default": "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
              "description": "CSS linear-gradient(...) string, or null for a solid color. See /api/options.json for presets."
            }
          },
          {
            "name": "windowChrome",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "macos",
                "macos-outline",
                "macos-gray",
                "windows",
                "none"
              ],
              "default": "macos"
            }
          },
          {
            "name": "windowTitle",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100,
              "default": "Untitled-1"
            }
          },
          {
            "name": "showWatermark",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          },
          {
            "name": "shadow",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "none",
                "sm",
                "md",
                "lg",
                "bottom"
              ],
              "default": "lg"
            }
          },
          {
            "name": "borderStyle",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "none",
                "solid",
                "glass"
              ],
              "default": "none"
            }
          },
          {
            "name": "aspectRatio",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "auto",
                "16:9",
                "4:3",
                "1:1"
              ],
              "default": "auto"
            }
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "png",
                "svg"
              ],
              "default": "png"
            }
          },
          {
            "name": "scale",
            "in": "query",
            "schema": {
              "type": "integer",
              "enum": [
                1,
                2,
                4,
                6
              ],
              "default": 2,
              "description": "PNG pixel density multiplier. Ignored for SVG."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rendered image",
            "content": {
              "image/png": {},
              "image/svg+xml": {}
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Render failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Render a code image from a JSON body",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "code"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "maxLength": 20000,
                    "description": "The source code to render. Required."
                  },
                  "language": {
                    "type": "string",
                    "enum": [
                      "javascript",
                      "typescript",
                      "tsx",
                      "jsx",
                      "python",
                      "java",
                      "cpp",
                      "c",
                      "csharp",
                      "php",
                      "ruby",
                      "go",
                      "rust",
                      "swift",
                      "kotlin",
                      "dart",
                      "html",
                      "css",
                      "scss",
                      "json",
                      "yaml",
                      "xml",
                      "sql",
                      "bash",
                      "powershell",
                      "markdown",
                      "vue",
                      "svelte",
                      "graphql",
                      "dockerfile",
                      "toml",
                      "lua",
                      "r",
                      "scala",
                      "elixir",
                      "haskell",
                      "zig"
                    ],
                    "default": "javascript"
                  },
                  "theme": {
                    "type": "string",
                    "enum": [
                      "github-dark",
                      "dracula",
                      "one-dark-pro",
                      "nord",
                      "tokyo-night",
                      "catppuccin-mocha",
                      "catppuccin-macchiato",
                      "vesper",
                      "vitesse-dark",
                      "ayu-dark",
                      "houston",
                      "synthwave-84",
                      "night-owl",
                      "poimandres",
                      "andromeeda",
                      "material-theme-darker",
                      "material-theme-ocean",
                      "material-theme-palenight",
                      "slack-dark",
                      "aurora-x",
                      "rose-pine",
                      "rose-pine-moon",
                      "monokai",
                      "solarized-dark",
                      "min-dark",
                      "everforest-dark",
                      "gruvbox-dark-hard",
                      "kanagawa-dragon",
                      "github-light",
                      "catppuccin-latte",
                      "vitesse-light",
                      "rose-pine-dawn",
                      "min-light",
                      "solarized-light",
                      "everforest-light",
                      "slack-ochin",
                      "one-light",
                      "snazzy-light"
                    ],
                    "default": "github-dark"
                  },
                  "fontFamily": {
                    "type": "string",
                    "enum": [
                      "jetbrains-mono",
                      "fira-code",
                      "geist-mono",
                      "source-code-pro",
                      "cascadia-code",
                      "ibm-plex-mono",
                      "monaspace-neon"
                    ],
                    "default": "jetbrains-mono",
                    "description": "Hosted renders always use JetBrains Mono; other values apply in the web editor via share links."
                  },
                  "fontSize": {
                    "type": "integer",
                    "minimum": 10,
                    "maximum": 28,
                    "default": 14
                  },
                  "lineNumbers": {
                    "type": "boolean",
                    "default": false
                  },
                  "lineNumberStart": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 1
                  },
                  "tabSize": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8,
                    "default": 2
                  },
                  "padding": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 256,
                    "default": 64,
                    "description": "Space around the code window, in px."
                  },
                  "borderRadius": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 48,
                    "default": 16
                  },
                  "backgroundVisible": {
                    "type": "boolean",
                    "default": true
                  },
                  "backgroundOpacity": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100,
                    "default": 100
                  },
                  "backgroundColor": {
                    "type": "string",
                    "pattern": "^#[0-9a-fA-F]{3,8}$",
                    "default": "#6B5CE7",
                    "description": "Solid background. Used when backgroundGradient is null."
                  },
                  "backgroundGradient": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "default": "linear-gradient(135deg, #667eea 0%, #764ba2 100%)",
                    "description": "CSS linear-gradient(...) string, or null for a solid color. See /api/options.json for presets."
                  },
                  "windowChrome": {
                    "type": "string",
                    "enum": [
                      "macos",
                      "macos-outline",
                      "macos-gray",
                      "windows",
                      "none"
                    ],
                    "default": "macos"
                  },
                  "windowTitle": {
                    "type": "string",
                    "maxLength": 100,
                    "default": "Untitled-1"
                  },
                  "showWatermark": {
                    "type": "boolean",
                    "default": false
                  },
                  "shadow": {
                    "type": "string",
                    "enum": [
                      "none",
                      "sm",
                      "md",
                      "lg",
                      "bottom"
                    ],
                    "default": "lg"
                  },
                  "borderStyle": {
                    "type": "string",
                    "enum": [
                      "none",
                      "solid",
                      "glass"
                    ],
                    "default": "none"
                  },
                  "aspectRatio": {
                    "type": "string",
                    "enum": [
                      "auto",
                      "16:9",
                      "4:3",
                      "1:1"
                    ],
                    "default": "auto"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "png",
                      "svg"
                    ],
                    "default": "png"
                  },
                  "scale": {
                    "type": "integer",
                    "enum": [
                      1,
                      2,
                      4,
                      6
                    ],
                    "default": 2,
                    "description": "PNG pixel density multiplier. Ignored for SVG."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The rendered image",
            "content": {
              "image/png": {},
              "image/svg+xml": {}
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Render failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/options.json": {
      "get": {
        "summary": "List accepted themes, languages, fonts, gradients, and enums",
        "responses": {
          "200": {
            "description": "Option catalog",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "code",
          "hint"
        ],
        "description": "Returned for every 4xx and 5xx response, always as application/json.",
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable description of what went wrong."
          },
          "code": {
            "type": "string",
            "description": "Stable machine-readable identifier — branch on this, not on the message text.",
            "enum": [
              "missing_code",
              "invalid_state",
              "invalid_json",
              "render_failed"
            ]
          },
          "hint": {
            "type": "string",
            "description": "Suggested next step to resolve the error."
          }
        },
        "examples": [
          {
            "error": "\"code\" is required (string, max 20000 chars)",
            "code": "missing_code",
            "hint": "Pass the snippet as the \"code\" field (POST body) or ?code= (GET). See https://codetoimage.com/api/openapi.json"
          }
        ]
      }
    }
  }
}