# Translate a File

`POST /translate_file`

Authentication: no security requirement declared for this operation.

Request body: multipart/form-data (required)

Type: object

- `file` (required)
  Type: string, binary
  
  File to translate

- `source` (required)
  Type: string
  
  Source language code  or "auto" for auto detection
  
  Example:
  
  ```json
  "en"
  ```

- `target` (required)
  Type: string
  
  Target language code
  
  Example:
  
  ```json
  "es"
  ```

- `api_key` (optional)
  Type: string
  
  API key
  
  Example:
  
  ```json
  "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  ```

Responses:

- 200: Translated file

Content type: application/json

Type: object

Schema: [translate-file](https://sourcey-libretranslate.pages.dev/es/api/models/translate-file/index.md)

- `translatedFileUrl` (optional)
  Type: string
  
  Translated file url

- 400: Invalid request

Content type: application/json

Type: object

Schema: [error-response](https://sourcey-libretranslate.pages.dev/es/api/models/error-response/index.md)

- `error` (optional)
  Type: string
  
  Error message

- 403: Banned

Content type: application/json

Type: object

Schema: [error-response](https://sourcey-libretranslate.pages.dev/es/api/models/error-response/index.md)

- `error` (optional)
  Type: string
  
  Error message

- 429: Slow down

Content type: application/json

Type: object

Schema: [error-slow-down](https://sourcey-libretranslate.pages.dev/es/api/models/error-slow-down/index.md)

- `error` (optional)
  Type: string
  
  Reason for slow down

- 500: Translation error

Content type: application/json

Type: object

Schema: [error-response](https://sourcey-libretranslate.pages.dev/es/api/models/error-response/index.md)

- `error` (optional)
  Type: string
  
  Error message

## Examples

### cURL

```bash
curl -X POST 'https://libretranslate.com/translate_file' \
  --form-string 'source=en' \
  --form-string 'target=es' \
  --form-string 'api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
```

### JavaScript

```javascript
const form = new FormData();
form.append('source', 'en');
form.append('target', 'es');
form.append('api_key', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
const response = await fetch('https://libretranslate.com/translate_file', {
  method: 'POST',
  headers: {},
  body: form,
});
console.log(await response.text());
```

### Python

```python
import requests
from contextlib import ExitStack

with ExitStack() as stack:
    files = [
        ('source', (None, 'en')),
        ('target', (None, 'es')),
        ('api_key', (None, 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')),
    ]
    response = requests.request('POST', 'https://libretranslate.com/translate_file', headers={}, files=files)
    print(response.text)
```
