Langsung ke konten
POST AI agent ready /v1/code/detect

Code Language Detect API - Identify Source Language

Scores a snippet against language-specific syntactic patterns (keywords, operators, common library calls) and returns the top match with a 0-1 confidence plus up to 3 alternative candidates. Supports javascript, typescript, python, go, rust, java, ruby, php, sql, html, css.

Parameters

stringrequired

Source code snippet to classify.

Code examples

curl -X POST https://api.botoi.com/v1/code/detect \
  -H "Content-Type: application/json" \
  -d '{"code":"const fetchUser = async (id) => {\n  const res = await fetch(`/users/${id}`);\n  return res.json();\n};"}'

When to use this API

Auto-highlight code in chat or comment threads

When a user pastes code into a support ticket or Slack channel, detect the language and apply the matching highlighter theme automatically. Saves the user from typing ```python each time.

Route ingested snippets by language

In a code-search product, classify each incoming file and route JavaScript through one parsing pipeline and Python through another. Improves indexing accuracy when file extensions are missing or wrong.

Fingerprint LLM-generated code

When LLM responses include code blocks without fences, detect the language before sending it to /v1/code/format. Avoids running a JavaScript formatter on Python code.

Frequently asked questions

Which languages are supported?
JavaScript, TypeScript, Python, Go, Rust, Java, Ruby, PHP, SQL, HTML, and CSS. Additional languages would be ignored and return language:"unknown" when no pattern scores above zero.
How does TypeScript versus JavaScript detection work?
TypeScript is checked before JavaScript. Snippets with explicit type annotations (: string, : number, interface X, type X =), generic syntax, or as-casts score as TypeScript. Plain JS with no type annotations falls through to JavaScript.
What does confidence mean?
A 0-1 score normalized against the top-scoring language. 1 means the scores are unambiguous; 0.5 means a close second exists. Check the alternatives array when confidence is below 0.8.
How much code do I need to send?
A few distinctive lines are enough for high-confidence detection. Single-line snippets can be ambiguous (e.g., "x = 5" matches many languages).
Does this handle mixed-content files?
Basic cases (PHP embedded in HTML) score PHP because the signal is strong. Vue/Svelte single-file components may score as HTML since the framework markers are subtle.

Get your API key

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