# Detect Language of Text

`POST /detect`

Authentication: no security requirement declared for this operation.

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

Type: object

- `q` (required)
  Type: string
  
  Text to detect
  
  Example:
  
  ```json
  "What language is this?"
  ```

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

Responses:

- 200: Detections

Content type: application/json

Type: array

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

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

- 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: Detection 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/detect' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw 'q=What%20language%20is%20this%3F&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
```

### JavaScript

```javascript
const response = await fetch('https://libretranslate.com/detect', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
  },
  body: 'q=What%20language%20is%20this%3F&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
});

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

### Python

```python
import requests

response = requests.post(
    'https://libretranslate.com/detect',
    data='q=What%20language%20is%20this%3F&api_key=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.encode('utf-8'),
    headers={
        'Content-Type': 'application/x-www-form-urlencoded',
    },
)
print(response.text)
```
