# Create embeddings

`POST https://my.neuronai.uz/api/v1/embeddings`

Справочник API › Эмбеддинги

Returns a 1024-dimensional dense vector per input. OpenAI-compatible — set your OpenAI SDK's base URL to `{app}/api/v1` and use your API key. Billed per input token.

**Authentication:** `Authorization: Bearer <API key>`, a key with `embeddings:write`.

**Pricing:** per 1K tokens: Input 0.1 credits.

## Тело запроса (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `model` | string | Yes | At most 128 characters. |
| `encoding_format` | string \| null | No | Only float vectors are served; base64 is an OpenAI option we do not support. One of `float`, `null`. |
| `input` | object | Yes | The text to embed: one string, or a list of strings for a batch. |

## Ответ (200, `application/json`)

One embedding per input, in the order of `input`. `usage.prompt_tokens` is what is billed.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | Yes |  |
| `model` | string | Yes |  |
| `data` | object[] | Yes |  |
| `data[].object` | string | Yes |  |
| `data[].index` | integer | Yes |  |
| `data[].embedding` | number[] | Yes |  |
| `usage` | object | Yes |  |
| `usage.prompt_tokens` | integer | Yes |  |
| `usage.total_tokens` | integer | Yes |  |

```json
{
  "object": "list",
  "model": "gemma-4-26b-a4b",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        0.0123
      ]
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "total_tokens": 42
  }
}
```

### Заголовки

| Header | Type | Description |
| --- | --- | --- |
| `X-Cost` | number | The price billed, in credits. |
| `X-Request-Id` | string | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
| `X-RateLimit-Limit` | integer | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
| `X-RateLimit-Remaining` | integer | How many of them are left this minute. |

## Ошибки

Every error has the same JSON shape:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "The request is malformed or failed validation.",
    "param": null
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

| Status | Meaning |
| --- | --- |
| 401 | The API key is missing or not recognized (`invalid_api_key`), revoked (`api_key_revoked`), disabled (`api_key_disabled`) or expired (`api_key_expired`). |
| 402 | Not enough balance (`insufficient_balance`), or over the key's monthly spend limit (`spend_limit_exceeded`). Nothing is charged. |
| 403 | The key lacks the permission this endpoint needs (`insufficient_permissions`), or the client IP is not in its allowlist (`ip_not_allowed`). |
| 404 | `model` is not an embedding model this API serves: `model_not_found`. |
| 422 | The request failed validation (`invalid_request`), it has too many inputs (`batch_too_large`), an input is too long (`input_too_large`), or the model refused an input (`upstream_rejected_input`). Nothing is charged. |
| 429 | The model is busy (`upstream_rate_limited`), or a rate or concurrency limit was reached (`rate_limit_exceeded`, `concurrency_limit_exceeded`). Retry after `Retry-After` seconds. Nothing is charged. |
| 502 | The embedding model failed or could not be reached: `upstream_error`. Nothing is charged. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
curl -X POST "https://my.neuronai.uz/api/v1/embeddings" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your-api-key>" \
  -d '{
    "model": "bge-m3",
    "input": "Toshkent bugun qanday?"
  }'
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";

const client = new NeuronAI();

const result = await client.embeddings.create({
    model: "bge-m3",
    input: "Toshkent bugun qanday?",
});

console.log(result.data[0]?.embedding.length);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

result = client.embeddings.create(model="bge-m3", input="Toshkent bugun qanday?")

print(len(result.data[0].embedding))
```

### PHP SDK

```php
$client = new \Naiuz\NeuronAI();

$result = $client->embeddings->create([
    'model' => 'bge-m3',
    'input' => 'Toshkent bugun qanday?',
]);

echo count($result->data[0]->embedding), PHP_EOL;
```

### Python (OpenAI SDK)

```python
from openai import OpenAI

client = OpenAI(base_url="https://my.neuronai.uz/api/v1", api_key="<your-api-key>")

result = client.embeddings.create(
    model="bge-m3",
    input="Toshkent bugun qanday?",
)

print(len(result.data[0].embedding))
```

### JavaScript (OpenAI SDK)

```javascript
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://my.neuronai.uz/api/v1',
  apiKey: '<your-api-key>',
});

const { data } = await client.embeddings.create({
  model: 'bge-m3',
  input: 'Toshkent bugun qanday?',
});
```

---

Source: https://docs.neuronai.uz/ru/api/reference/embeddings/create-embedding
