Skip to content

Legesher Bridge API

The Legesher Bridge API localizes Python source between human languages over HTTP. It runs the same open-source engine and language packs as the editor extension and the command line. Submitted source is never logged and never used for training.

  • Base URL: https://api.legesher.io
  • Version: every route lives under /v1. See Versioning.
  • Format: JSON requests and JSON responses.
  • Reference: every endpoint, request and response is in the endpoint reference, generated from the OpenAPI document.

Most requests take an API key. Create an account at app.legesher.io, open Your keys, and create a key. The key is shown once, so store it somewhere safe right away. Keys and sign-in describes the other way to get a key, from a command line or an editor.

Put the key in an environment variable for the examples on this page:

Terminal window
export LEGESHER_API_KEY="lgsh_live_..."

To try the API before you create an account, leave out the Authorization header. Translation, validation and explanation requests also work without a key, on a small anonymous trial.

Send the source, the language it is written in, and the language to translate into. The language codes are the ones GET /v1/languages lists.

Terminal window
curl https://api.legesher.io/v1/translate \
-H "Authorization: Bearer $LEGESHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"source": "def greet(name):\n print(\"Hello,\", name)\n\ngreet(\"Ada\")\n",
"source_lang": "en",
"target_lang": "es"
}'

The response holds the translated source and says how it was produced:

{
"translated_source": "definir greet(name):\n imprimir(\"Hello,\", name)\n\ngreet(\"Ada\")\n",
"source_lang": "en",
"target_lang": "es",
"python_version": "3.13",
"pivoted": false,
"mode_used": "standard",
"mode_fallback": false,
"fallback_reason": null,
"metadata": null
}

The language pack translates Python’s own words: def becomes definir and print becomes imprimir. Your names and strings stay as you wrote them. A few more things to know:

  • python_version chooses the language pack: 3.10, 3.11, 3.12, 3.13 (the default) or 3.14.
  • Between two languages other than English, the API translates through English and sets "pivoted": true.
  • POST /v1/translate/snippet takes the same body, for a fragment that is not a whole file.
  • With "enhanced": true on a paid plan, a model pass also translates comments, docstrings, string literals and suggested names. If that pass cannot run, you get the standard result with "mode_fallback": true.

Every error has the same shape: a machine-readable code and a message for people.

{
"error": {
"code": "unsupported_language",
"message": "Unsupported language code: 'xx'."
}
}
Status error.code What it means
401 unauthorized The key sent is malformed, unknown or revoked. Check the header reads Authorization: Bearer <key>.
402 tier_required The request needs a paid plan, for example "enhanced": true.
422 unsupported_language, validation_error A language code is not supported, or a field is missing or malformed. details lists each field.
429 rate_limited, quota_exceeded Too many requests in a short time (wait for Retry-After), or this month’s character allowance is used up.

Errors and limits lists every code and the headers that report your usage.