コンテンツへスキップ
POST AI agent ready /v1/code/highlight

Code Highlight API - Syntax Highlight to HTML

Tokenizes the input code (keywords, strings, comments, numbers, identifiers, punctuation) and wraps each token in a colored span. Returns a self-contained <pre><code> block with inline styles plus the language label. Supports JavaScript, Python, SQL, and other BPE-friendly languages.

Parameters

stringrequired

Source code to highlight.

stringrequired

Language hint that drives the keyword set.

string

Color theme.

Code examples

curl -X POST https://api.botoi.com/v1/code/highlight \
  -H "Content-Type: application/json" \
  -d '{"code":"def hello(name):\n    return f\"Hi {name}!\"","language":"python","theme":"light"}'

When to use this API

Render code on a static site without client-side JS

Call this endpoint at build time for each code block and inline the returned HTML. Your site renders highlighted code on first paint with zero JS bundle overhead for Prism or Shiki.

Generate screenshot-ready code snippets

Combine with /v1/screenshot/capture: highlight the code, pass the HTML through the screenshot endpoint, and get a social-shareable image of your code snippet.

Email-friendly code in transactional messages

Email clients strip <script> tags but allow inline styles. The self-contained output from this endpoint renders as-is in Gmail, Outlook, and Apple Mail with no extra processing.

Frequently asked questions

Which themes are available?
dark (default) uses a Material-inspired palette on a dark background. light uses a high-contrast palette on a light background. Pass theme:"light" for embedding on bright pages.
Which languages have accurate tokenization?
JavaScript, TypeScript, Python, and SQL have dedicated keyword sets. Other languages fall back to the JS keyword set, which still colors strings, comments, and numbers correctly.
Is the HTML safe to embed directly?
Yes. The code text is HTML-escaped before wrapping; &, <, >, and " are converted to entities. You can safely set innerHTML with the response.
Can I pass my own CSS classes?
Token classes (token-keyword, token-string, etc.) are always emitted. The inline style on each span takes precedence; override it with a more specific selector in your stylesheet if needed.
What is the size limit?
There is no hard limit on the request, but very large snippets (100+ KB) will be slow. For documentation sites, highlight code at build time and cache the HTML.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.