# text-embedding-3-large

Source: [text-embedding-3-large](<https://docs.gptunnel.ru/en/embedding/text-embedding-3-large/>)

<a id="_top"></a>
<a id="create-embeddings"></a>
## Create embeddings

`POST https://gptunnel.ru/v1/embeddings`

The endpoint returns a numeric vector for the input text. Without `dimensions`, text-embedding-3-large returns 3072 numbers.

### Request headers

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `Authorization` | `string` | Required | GPTunneL API key |

### Request body

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `model`<a id="embedding-request-model"></a> | `string` | Required | Model ID: text-embedding-3-large |
| `input`<a id="embedding-request-input"></a> | `string` | Required | Text to embed. Send a non-empty string |
| `dimensions`<a id="embedding-request-dimensions"></a> | `integer` | Optional | Number of elements in the vector. Default: 3072. This example uses 2048 |
| `useWalletBalance`<a id="embedding-request-useWalletBalance"></a> | `boolean` | Optional | Set to true to use your personal balance |

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

Set your [API key](<https://docs.gptunnel.ru/en/#get-an-api-key>) in the `GPTUNNEL_API_KEY` environment variable.

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

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

body = {
    'model': 'text-embedding-3-large',
    'input': 'A blue sky.',
    'dimensions': 2048,
}
request = Request(
    'https://gptunnel.ru/v1/embeddings',
    headers={
        'Authorization': os.environ['GPTUNNEL_API_KEY'],
        'Content-Type': 'application/json',
    },
    data=json.dumps(body).encode('utf-8'),
    method='POST',
)
with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

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

```bash
curl --fail-with-body --silent --show-error \
  --url 'https://gptunnel.ru/v1/embeddings' \
  --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \
  --json '{
  "model": "text-embedding-3-large",
  "input": "A blue sky.",
  "dimensions": 2048
}'
```

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

```javascript
const response = await fetch('https://gptunnel.ru/v1/embeddings', {
  method: 'POST',
  headers: {
    Authorization: process.env.GPTUNNEL_API_KEY,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "model": "text-embedding-3-large",
    "input": "A blue sky.",
    "dimensions": 2048
  }),
})
if (!response.ok) throw new Error(await response.text())
console.log(await response.json())
```

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

This request returns 2048 numbers in `data[0].embedding`. The example shows the first three. `usage.prompt_tokens` gives the input token count, and `usage.total_cost` gives the request cost in rubles. This response omits `usage.total_tokens`.

```json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        0.004749298095703125,
        -0.047576904296875,
        0.0045928955078125
      ]
    }
  ],
  "model": "text-embedding-3-large",
  "usage": {
    "prompt_tokens": 4,
    "completion_tokens": 0,
    "prompt_cost": 0.00028000000000000003,
    "completion_cost": 0,
    "total_cost": 0.00028000000000000003
  }
}
```

<a id="errors"></a>
### Errors

| HTTP | What to check |
| --- | --- |
| 400 | If the response says `model is required`, include `model` in the request body. |
| 401 | Send a valid API key in the `Authorization` header. |
| 402 | Check the [balance of the selected account](<https://docs.gptunnel.ru/en/getting-started/balance/>). |
| 404 | For `invalid_model_error`, check the model ID against the [catalog for your key](<https://docs.gptunnel.ru/en/api/models/>). |
| 422 | For `invalid_input` with `error.param: "input"`, send non-empty text in [`input`](<https://docs.gptunnel.ru/en/embedding/text-embedding-3-large/#embedding-request-input>). |

[Example HTTP 422 response body](<https://docs.gptunnel.ru/en/embedding/text-embedding-3-small/#errors>)
