Skip to content

Statically validate a (possibly translated) source file

POST
/v1/validate
curl --request POST \
--url https://api.legesher.io/v1/validate \
--header 'Content-Type: application/json' \
--data '{ "language": "en", "python_version": "3.10", "source": "example" }'

Syntax-check submitted source. compile() only, never executed.

The verdict is produced under the server interpreter’s grammar, disclosed in the response as grammar_used; python_version selects the language pack for reverse translation only. If your target version differs from grammar_used, version-specific constructs may validate (or fail) against the wrong grammar.

Media type application/json
ValidateRequest

A (possibly translated) Python source file to syntax-check.

object
language
Language

Language the source is written in (ISO 639 code).

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

Python grammar version used to select the language pack.

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

Python source text to validate.

string
>= 1 characters <= 2000000 characters

Successful Response

Media type application/json
ValidateResponse

Outcome of a static (compile-only, never-executed) syntax check.

object
grammar_used
required
Grammar Used

CPython grammar version that actually judged the source: the interpreter running the service. When this differs from python_version, a construct that is valid in only one of the two versions can get a verdict that does not transfer to your target version (e.g. PEP 695 type aliases, 3.12+).

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
language
required
Language
string
python_version
required
Python Version

The requested version, echoed back. It selects the language pack for reverse translation; it does not select the grammar the syntax verdict is produced under (see grammar_used).

string
Allowed values: 3.10 3.11 3.12 3.13 3.14
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.