# Get a price quote

Source: [Get a price quote](<https://docs.gptunnel.ru/en/creative-lab/price/>)

<a id="_top"></a>
> **Note: Authentication**
>
> You need an [API key](<https://docs.gptunnel.ru/en/#get-an-api-key>) to request a quote.

<a id="calculate-the-price"></a>
## Calculate the price

`POST https://gptunnel.ru/api/v2/media/price`

Send `{ model, prompt, params, inputs }` to get the generation price. A quote is free and does not start a task. The API calculates the quote the same way it calculates the charge when you create the task.

For `kling-v3`, include `prompt` at the top level, alongside `model`. If you omit it or put it only inside `params`, the API returns [400 ERR\_EMPTY\_PROMPT](<https://docs.gptunnel.ru/en/creative-lab/errors/#error-empty-prompt>).

For text-to-speech models, pricing depends on the voice and the length of the text. Send the same `prompt` and `params.voice` that you will use for the task. The API checks the voice just as it does when creating a task. An unknown or unavailable voice returns HTTP `400`.

Use the full text you plan to submit. Quotes and task creation use the same rules for required prompts and length limits. For models that charge per prompt token, the text also affects the price. Check the [model catalog](<https://docs.gptunnel.ru/en/creative-lab/models/>) for each model’s requirements.

### Request body

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `model`<a id="request-model"></a> | `string` | Required | Model identifier. |
| `prompt`<a id="request-prompt"></a> | `string` | For some models | Text to use for generation. The prompt field in the model catalog specifies whether it is required. If specified, max\_length limits the number of characters and max\_bytes limits the number of UTF-8 bytes. |
| `params`<a id="request-params"></a> | `object` | Optional | Generation settings, such as duration and resolution. These may affect the price. |
| `inputs`<a id="request-inputs"></a> | `object` | Optional | Input files grouped by role, in the same format as for task creation. The API counts attachments and may read linked files to measure their dimensions or duration and check limits. Send the same inputs that you will use for generation. |

For image-based generation with `kling-image-v4-product`, include both the text in `prompt` and the image URL in the `inputs.image` array. Without an image, the method returns HTTP `400` with `details[].key: "image"`. If you supply an image but omit the text, the error points to `prompt` and contains `ERR_EMPTY_PROMPT`.

<a id="example-request"></a>
### Example request

The examples read the key from the `GPTUNNEL_API_KEY` environment variable. Choose 5 or 10 seconds. The copied request uses that value for `params.duration`.

<a id="tab-panel-0-0"></a>
**5 s**

<a id="tab-panel-1-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

body = {
    'model': 'kling-v3',
    'prompt': "A blue sky above the city's skyline.",
    'params': {'resolution': '1080p', 'duration': 5, 'aspect_ratio': '16:9'},
}
request = Request(
    'https://gptunnel.ru/api/v2/media/price',
    method='POST',
    headers={
        'Authorization': os.environ['GPTUNNEL_API_KEY'],
        'Content-Type': 'application/json',
    },
    data=json.dumps(body).encode('utf-8'),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-1-1"></a>
**cURL**

```bash
curl --fail-with-body --request POST \
  --url 'https://gptunnel.ru/api/v2/media/price' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v3",
  "prompt": "A blue sky above the city'\''s skyline.",
  "params": {
    "resolution": "1080p",
    "duration": 5,
    "aspect_ratio": "16:9"
  }
}'
```

<a id="tab-panel-1-2"></a>
**JavaScript (Node.js)**

```javascript
const apiKey = process.env.GPTUNNEL_API_KEY
if (!apiKey) throw new Error("Set GPTUNNEL_API_KEY")

const response = await fetch('https://gptunnel.ru/api/v2/media/price', {
  method: 'POST',
  headers: {
    Authorization: apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "model": "kling-v3",
  "prompt": "A blue sky above the city's skyline.",
  "params": {
    "resolution": "1080p",
    "duration": 5,
    "aspect_ratio": "16:9"
  }
}),
})

if (!response.ok) throw new Error('HTTP ' + response.status + ': ' + await response.text())

console.log(await response.json())
```

<a id="tab-panel-0-1"></a>
**10 s**

<a id="tab-panel-2-0"></a>
**Python**

```python
import json
import os
from urllib.request import Request, urlopen

body = {
    'model': 'kling-v3',
    'prompt': "A blue sky above the city's skyline.",
    'params': {'resolution': '1080p', 'duration': 10, 'aspect_ratio': '16:9'},
}
request = Request(
    'https://gptunnel.ru/api/v2/media/price',
    method='POST',
    headers={
        'Authorization': os.environ['GPTUNNEL_API_KEY'],
        'Content-Type': 'application/json',
    },
    data=json.dumps(body).encode('utf-8'),
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

<a id="tab-panel-2-1"></a>
**cURL**

```bash
curl --fail-with-body --request POST \
  --url 'https://gptunnel.ru/api/v2/media/price' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v3",
  "prompt": "A blue sky above the city'\''s skyline.",
  "params": {
    "resolution": "1080p",
    "duration": 10,
    "aspect_ratio": "16:9"
  }
}'
```

<a id="tab-panel-2-2"></a>
**JavaScript (Node.js)**

```javascript
const apiKey = process.env.GPTUNNEL_API_KEY
if (!apiKey) throw new Error("Set GPTUNNEL_API_KEY")

const response = await fetch('https://gptunnel.ru/api/v2/media/price', {
  method: 'POST',
  headers: {
    Authorization: apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "model": "kling-v3",
  "prompt": "A blue sky above the city's skyline.",
  "params": {
    "resolution": "1080p",
    "duration": 10,
    "aspect_ratio": "16:9"
  }
}),
})

if (!response.ok) throw new Error('HTTP ' + response.status + ': ' + await response.text())

console.log(await response.json())
```

<a id="example-response"></a>
### Example response

This five-second quote returned 210 RUB. Check `price` and `currency` in your own response for the amount that applies to your key. Kling returns `params.duration` as a string.

```json
{
  "code": 0,
  "model": "kling-v3",
  "price": 210,
  "currency": "RUB",
  "params": { "resolution": "1080p", "duration": "5", "aspect_ratio": "16:9" },
  "breakdown": ["42 × 5 = 210.0000"]
}
```

> **Note: Discounts are included in price**
>
> `price` includes the model discount and any personal discount. See below for cases where the quote is approximate. When the discount is nonzero, the response includes `discount_percent` and the original `price_before_discount`. The last line of `breakdown` shows the calculation as `price before discount × (1 − N%) = total`. The [model list](<https://docs.gptunnel.ru/en/creative-lab/models/>) shows the same discounted price. To see the amount actually charged, check `price` in the [task object](<https://docs.gptunnel.ru/en/creative-lab/get-task/>).

> **Note: How to read the breakdown**
>
> `breakdown` shows each step of the calculation, for example `["170 × 3 = 510", "510 × (1 − 10%) = 459"]`. It is always present when the discount is nonzero, with the discount applied on the last line. Without a discount, only models with a `pricing` rule return `breakdown`. See the [model list](<https://docs.gptunnel.ru/en/creative-lab/models/>). Models with a single fixed price per generation omit the field in this case.

> **Note: Response params show the settings used for pricing**
>
> The server returns the settings it used to calculate the price and will send to the provider. These include your choices, defaults for omitted values and any values fixed by the model. See the [model list](<https://docs.gptunnel.ru/en/creative-lab/models/>). `ignored_params` lists keys the server ignored. Normalization can also change the type of a value. For example, Kling returns duration as a string.

> **Note: Send only the fields accepted for a quote**
>
> From your task creation request, copy `model`, `prompt`, `params` and `inputs`. Sending `webhook_url`, `idempotency_key` or `wait` returns HTTP `400` with `code: 3`.
>
>
>
> Unknown keys and keys with values fixed by the model inside `params` are listed in `ignored_params`. An invalid value for a configurable parameter returns HTTP `400`. See [Create a task](<https://docs.gptunnel.ru/en/creative-lab/create-task/>) for the rules and an example.

> **Caution: When the quote is approximate**
>
> If pricing depends on input dimensions or duration, the API tries to measure the files at the URLs you provide. For example, `krea-3` counts a 1200 × 630 image as `ref_mp_1k: 0.756`.
>
>
>
> If the measurement fails, the API may use an estimate or return an error. This depends on the model and the parameter it needs to calculate the price.
>
>
>
> A successful quote does not guarantee that the input file will be available for generation. Provide working URLs and use the same files and settings when you create the task.
