# Translate Text

`POST /translate`

Authentication: no security requirement declared for this operation.

Request body: application/x-www-form-urlencoded (required)

Type: object

- `q` (required)
  Type: unknown
  
  Text(s) to translate
  
  oneOf:
    Type: string
    
    Example:
    
    ```json
    "Hello world!"
    ```
  
    Type: array
    
    Example:
    
    ```json
    [
      "Hello world!"
    ]
    ```
    
    Items:
      Type: unknown

- `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"
  ```

- `format` (optional)
  Type: string
  
  Format of source text:
   * `text` - Plain text
   * `html` - HTML markup
  
  
  default: "text"
  
  enum: ["text","html"]
  
  Example:
  
  ```json
  "text"
  ```

- `alternatives` (optional)
  Type: integer
  
  Preferred number of alternative translations
  
  default: 0
  
  Example:
  
  ```json
  3
  ```

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

Responses:

- 200: Translation

Content type: application/json

Type: object

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

- `alternatives` (optional)
  Type: unknown
  
  Alternative translations
  
  oneOf:
    Type: array
    
    Items:
      Type: string
  
    Type: array
    
    Items:
      Type: array
      
      Items:
        Type: string

- `detectedLanguage` (optional)
  Type: unknown
  
  oneOf:
    Type: object
    
    - `confidence` (optional)
      Type: number, float
      
      Confidence value
      
      minimum: 0
      
      maximum: 100
      
      Example:
      
      ```json
      100
      ```
    
    - `language` (optional)
      Type: string
      
      Language code
  
    Type: array
    
    Items:
      Type: object
      
      - `confidence` (optional)
        Type: number, float
        
        Confidence value
        
        minimum: 0
        
        maximum: 100
        
        Example:
        
        ```json
        100
        ```
      
      - `language` (optional)
        Type: string
        
        Language code

- `translatedText` (required)
  Type: unknown
  
  Translated text(s)
  
  oneOf:
    Type: string
  
    Type: array
    
    Items:
      Type: unknown

- 400: Invalid request

Content type: application/json

Type: object

Schema: [error-response](https://sourcey-libretranslate.pages.dev/it/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/it/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/it/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/it/api/models/error-response/index.md)

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

## Examples

### cURL

```bash
curl -X POST 'https://libretranslate.com/translate' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw 'q=Hello%20world%21&source=en&target=es&format=text&alternatives=3&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
```

### JavaScript

```javascript
const response = await fetch('https://libretranslate.com/translate', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: 'q=Hello%20world%21&source=en&target=es&format=text&alternatives=3&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});

const data = await response.text();
```

### Python

```python
import requests

response = requests.post(
    'https://libretranslate.com/translate',
    data='q=Hello%20world%21&source=en&target=es&format=text&alternatives=3&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.encode('utf-8'),
    headers={
        'Content-Type': 'application/x-www-form-urlencoded',
    },
)
print(response.text)
```
