Skip to content

Engine facts for explaining code in a language

POST
/v1/explain
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.

Media type application/json
ExplainRequest

Code to gather explanation facts for.

object
code_lang
Code Lang

Language the code is written in.

string
default: en >= 2 characters <= 16 characters /^[a-z]{2,3}(-[A-Za-z0-9]+)?$/
explain_in
required
Explain In

Language the explanation will be written in.

string
>= 2 characters <= 16 characters /^[a-z]{2,3}(-[A-Za-z0-9]+)?$/
include_translation
Include Translation

Also return the source translated into explain_in.

boolean
python_version
Python Version

Python grammar version used to select the language packs.

string
default: 3.13
Allowed values: 3.10 3.11 3.12 3.13 3.14
source
required
Source

The code to explain.

string
>= 1 characters <= 2000000 characters

Successful Response

Media type application/json
ExplainResponse

Engine facts for explaining code; the calling model writes the prose.

object
code_lang
required
Code Lang
string
constructs
required
Constructs
Array<object>
ConstructMapping

One construct present in the code, mapped across both languages.

object
category
required
Category

Keywords | builtins | exceptions | reserved_words

string
construct
required
Construct

Canonical English term.

string
in_code_lang
required
In Code Lang

How the construct is spelled in the code’s language.

string
in_explain_lang
required
In Explain Lang

How the construct is spelled in the explanation language (the English spelling when the pack has no entry for it).

string
explain_in
required
Explain In
string
python_version
required
Python Version
string
Allowed values: 3.10 3.11 3.12 3.13 3.14
translated_source
Translated Source

The code translated into explain_in, when requested.

Any of:
string
validation
required
ExplainValidation

Static (compile-only, never-executed) validation of the code.

object
grammar_used
required
Grammar Used

CPython grammar version that judged the source: the server interpreter’s, the same as on /v1/validate.

string
issue

Present only when valid is false.

Any of:
SyntaxIssue

Location and message of a syntax problem (1-based line/column).

object
line
Line
Any of:
integer
message
required
Message
string
offset
Offset
Any of:
integer
valid
required
Valid
boolean

Example

{
"python_version": "3.10"
}
X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
X-Request-ID
string

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
Retry-After
integer

Seconds to wait before retrying. Usually sent with rate_limited; absent on quota_exceeded, which lasts until the UTC month resets.

X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.

Media type application/json
ErrorResponse

Envelope for every error response.

object
error
required
ErrorDetail

Machine-readable code + human message for one error.

object
code
required
Code

Machine-readable error code, e.g. ‘validation_error’, ‘unsupported_language’, ‘language_pack_not_found’, ‘payload_too_large’, ‘foundation_unavailable’, ‘invalid_source_code’, ‘internal_error’.

string
details
Details

Per-field breakdown (validation errors only).

Any of:
Array<object>
FieldIssue

One request-validation problem, stripped of the submitted input.

object
field
required
Field

Dotted location of the offending field.

string
message
required
Message

Human-readable description.

string
type
required
Type

Pydantic error type identifier.

string
message
required
Message

Human-readable explanation.

string

Example generated

{
"error": {
"code": "example",
"details": [
{
"field": "example",
"message": "example",
"type": "example"
}
],
"message": "example"
}
}
X-RateLimit-Limit
integer

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.

X-RateLimit-Remaining
integer

Requests remaining in the current rate window.

X-RateLimit-Reset
integer

Seconds until the rate limit fully resets.

X-Request-ID
string

Correlation id for this request: the validated inbound X-Request-ID when one was sent, else a server-minted UUID.

X-Usage-Characters-Remaining
integer

Characters left in the caller’s monthly budget.

X-Usage-Characters-Used
integer

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.