# Captcha

## Generate a QR Code

<mark style="color:blue;">`GET`</mark> `https://api.night-api.com/images/captcha`

#### Headers

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| authorization<mark style="color:red;">\*</mark> | String | Your API key |

#### Request Body

| Name     | Type   | Description                                                             |
| -------- | ------ | ----------------------------------------------------------------------- |
| codeSize | Number | <p>Size of the code to generate between 4 and 10 </p><p>Default : 6</p> |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{ 
    status: 200, 
    content: { 
        code: 'ju0bm1', 
        codeSize: 6, 
        image: { 
            type: 'Buffer', 
            data: [Array] 
        } 
    }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "status": 400,
    "content": "Invalid Key"
}
```

{% endtab %}
{% endtabs %}

```javascript
const axios = require("axios");
const { writeFileSync } = require('fs');

axios.get('https://api.night-api.com/images/captcha', {
    headers: {
        authorization: "Your API token"
    },
    data: {
        codeSize: 9 // Between 4 and 10 
    }
})
.then(async function (res) {
    console.log(res.data);
    writeFileSync(`${__dirname}/captcha.png`, Buffer.from(res.data.content.image, 'base64'));
})
```

Or with the module

```javascript
// Return: Promise

const { NightAPI } = require('night-api');
const api = new NightAPI('YOUR_API_KEY');

const captha = await api.captcha.generate(); // Generate captcha

// You can use this function for choose the number of caracters beetween 4 and 10

const captha = await api.captcha.generate(6);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.night-api.com/images/utils/captcha.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
