Engine facts for explaining code in a language
const url = 'https://api.legesher.io/v1/explain';const options = { method: 'POST', headers: {'Content-Type': 'application/json'}, body: '{"code_lang":"en","explain_in":"example","include_translation":false,"python_version":"3.10","source":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.legesher.io/v1/explain \ --header 'Content-Type: application/json' \ --data '{ "code_lang": "en", "explain_in": "example", "include_translation": false, "python_version": "3.10", "source": "example" }'Deterministic explanation material; the calling model writes the prose.
Construct-by-construct keyword mappings for the constructs actually
present in the code, plus a static (compile-only, never executed)
validation result with the grammar_used disclosure. REST parity with
the open legesher-mcp package’s explain_in_language tool.
Request Bodyrequired
Section titled “ Request Bodyrequired ”Code to gather explanation facts for.
object
Language the code is written in.
Language the explanation will be written in.
Also return the source translated into explain_in.
Python grammar version used to select the language packs.
The code to explain.
Responses
Section titled “ Responses ”Successful Response
Engine facts for explaining code; the calling model writes the prose.
object
One construct present in the code, mapped across both languages.
object
Keywords | builtins | exceptions | reserved_words
Canonical English term.
How the construct is spelled in the code’s language.
How the construct is spelled in the explanation language (the English spelling when the pack has no entry for it).
Static (compile-only, never-executed) validation of the code.
object
CPython grammar version that judged the source: the server interpreter’s, the same as on /v1/validate.
Example
{ "python_version": "3.10"}Headers
Section titled “ Headers ”Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.
An API key was sent and is not valid. A request with no key runs on the anonymous trial instead.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
The language has no pack for the requested Python version.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.
The request body or the source is over the size limit.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.
A field is missing or malformed, or a language code is not supported.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.
Too many requests, or this month’s character allowance is used up.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Seconds to wait before retrying. Usually sent with rate_limited; absent on quota_exceeded, which lasts until the UTC month resets.
Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.
The translation engine is unavailable.
Envelope for every error response.
object
Machine-readable code + human message for one error.
object
Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.
Per-field breakdown (validation errors only).
One request-validation problem, stripped of the submitted input.
object
Dotted location of the offending field.
Human-readable description.
Pydantic error type identifier.
Human-readable explanation.
Example generated
{ "error": { "code": "example", "details": [ { "field": "example", "message": "example", "type": "example" } ], "message": "example" }}Headers
Section titled “ Headers ”Requests permitted per minute for the caller’s tier. The X-RateLimit-* set is omitted when the tier’s rate is unlimited, and on a request refused before the caller is identified.
Requests remaining in the current rate window.
Seconds until the rate limit fully resets.
Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.
Characters left in the caller’s monthly budget.
Characters billed against the caller’s monthly budget, UTC month to date. The X-Usage-* pair is omitted when the budget is unlimited, and on a request refused before the caller is identified.