> For the complete documentation index, see [llms.txt](https://ai-pip.gitbook.io/ai-pip-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-pip.gitbook.io/ai-pip-docs/primery-ispolzovaniya-curl-python-javascript.md).

# Примеры использования (cURL, Python, JavaScript)

### cURL

**Текстовый запрос (автовыбор модели)**

```bash
curl -X POST https://d5daftde5irfpvduu5pm.wnq2w1o5.apigw.yandexcloud.net/api/chat \
  -H "Authorization: Bearer ВАШ_API_КЛЮЧ" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Привет!"}]}'
```

**Явное указание модели**

```bash
curl -X POST .../api/chat \
  -H "Authorization: Bearer ВАШ_API_КЛЮЧ" \
  -H "Content-Type: application/json" \
  -d '{"model":"deepseek/deepseek-v4-flash","messages":[{"role":"user","content":"Напиши код сортировки"}]}'
```

**Генерация изображения**

```bash
curl -X POST .../api/chat \
  -H "Authorization: Bearer ВАШ_API_КЛЮЧ" \
  -H "Content-Type: application/json" \
  -d '{"messages":[{"role":"user","content":"Нарисуй закат"}]}'
```

**Эмбеддинги**

```bash
curl -X POST .../api/embeddings \
  -H "Authorization: Bearer ВАШ_API_КЛЮЧ" \
  -H "Content-Type: application/json" \
  -d '{"input":"Привет, мир!"}'
```

### Python

```python
import requests

API_URL = "https://d5daftde5irfpvduu5pm.wnq2w1o5.apigw.yandexcloud.net/api"
HEADERS = {
    "Authorization": "Bearer ВАШ_API_КЛЮЧ",
    "Content-Type": "application/json"
}

# Текстовый запрос (автовыбор)
data = {"messages": [{"role": "user", "content": "Привет!"}]}
resp = requests.post(f"{API_URL}/chat", headers=HEADERS, json=data)
print(resp.json())

# Явное указание модели
data["model"] = "deepseek/deepseek-v4-flash"
resp = requests.post(f"{API_URL}/chat", headers=HEADERS, json=data)
print(resp.json())

# Генерация изображения
data_img = {"messages": [{"role": "user", "content": "Нарисуй закат"}]}
resp_img = requests.post(f"{API_URL}/chat", headers=HEADERS, json=data_img)
print(resp_img.json())  # ответ содержит "images"

# Эмбеддинги
emb_data = {"input": ["Привет", "Как дела?"]}
resp_emb = requests.post(f"{API_URL}/embeddings", headers=HEADERS, json=emb_data)
print(resp_emb.json())
```

### JavaScript&#x20;

```javascript
const API_URL = "https://d5daftde5irfpvduu5pm.wnq2w1o5.apigw.yandexcloud.net/api";
const headers = {
  "Authorization": "Bearer ВАШ_API_КЛЮЧ",
  "Content-Type": "application/json"
};

// Текстовый запрос (автовыбор)
fetch(`${API_URL}/chat`, {
  method: "POST",
  headers,
  body: JSON.stringify({ messages: [{ role: "user", content: "Привет!" }] })
})
  .then(r => r.json())
  .then(console.log);

// Явное указание модели
fetch(`${API_URL}/chat`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    model: "deepseek/deepseek-v4-flash",
    messages: [{ role: "user", content: "Напиши код..." }]
  })
})
  .then(r => r.json())
  .then(console.log);

// Генерация изображения
fetch(`${API_URL}/chat`, {
  method: "POST",
  headers,
  body: JSON.stringify({ messages: [{ role: "user", content: "Нарисуй закат" }] })
})
  .then(r => r.json())
  .then(console.log);

// Эмбеддинги
fetch(`${API_URL}/embeddings`, {
  method: "POST",
  headers,
  body: JSON.stringify({ input: ["Привет", "Мир"] })
})
  .then(r => r.json())
  .then(console.log);
```

### Обработка ошибок

API возвращает стандартные HTTP‑коды:

* `200` – успех.
* `400` – некорректный запрос (отсутствует `messages` и т.п.).
* `401` – неверный или отсутствующий API‑ключ.
* `403` – недостаточно токенов для операции (например, для генерации изображений).
* `429` – баланс пуст.
* `502` – все модели временно недоступны.

В теле ответа будет поле `error` с описанием проблемы.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ai-pip.gitbook.io/ai-pip-docs/primery-ispolzovaniya-curl-python-javascript.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
