API

API

By default, the API can be used without a key to make 30 requests per minute:
curl -d "q=cloudron%20ist%20wunderbar&source=de&target=en" -X POST https://translate.domain.com/translate

To lock the app and enforce use of a key, set the below in /app/data/env.sh:
export LT_REQUIRE_API_KEY_ORIGIN=true
export LT_REQ_LIMIT=0


Create Key

Use the ltmanage command to create an API key. On Cloudron, LibreTranslate runs as the cloudron user.
Run the following command using the dashboard Web Terminal to create an API with a limit of 120 requests per minute:
source /app/code/venv/bin/activate
ltmanage keys --api-keys-db-path /app/data/db/api_keys.db add 120

The key can be used as follows:
curl -d "q=cloudron%20ist%20wunderbar&api_key=f67d5afe-aa14-4d37-90f7-f7d9636b721e&source=de&target=en" -X POST https://translate.domain.com/translate

Existing API keys can also be listed with:
source /app/code/venv/bin/activate
ltmanage keys --api-keys-db-path /app/data/db/api_keys.db

and then also revoked with:
source /app/code/venv/bin/activate
ltmanage keys --api-keys-db-path /app/data/db/api_keys.db remove <key>