Простой строковый ввод
Самый простой способ использования API — это ввод строки:const response = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: 'What is the meaning of life?',
max_output_tokens: 9000,
}),
});
const result = await response.json();
console.log(result);
import requests
response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': 'What is the meaning of life?',
'max_output_tokens': 9000,
}
)
result = response.json()
print(result)
curl -X POST https://api.llmstore.ru/v1/responses \
-H "Authorization: Bearer YOUR_LLMSTORE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/o4-mini",
"input": "What is the meaning of life?",
"max_output_tokens": 9000
}'
Ввод структурированного сообщения
Для более сложных диалогов используйте формат массива сообщений:const response = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: [
{
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'Tell me a joke about programming',
},
],
},
],
max_output_tokens: 9000,
}),
});
const result = await response.json();
import requests
response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': [
{
'type': 'message',
'role': 'user',
'content': [
{
'type': 'input_text',
'text': 'Tell me a joke about programming',
},
],
},
],
'max_output_tokens': 9000,
}
)
result = response.json()
curl -X POST https://api.llmstore.ru/v1/responses \
-H "Authorization: Bearer YOUR_LLMSTORE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/o4-mini",
"input": [
{
"type": "message",
"role": "user",
"content": [
{
"type": "input_text",
"text": "Tell me a joke about programming"
}
]
}
],
"max_output_tokens": 9000
}'
Формат ответа
API возвращает структурированный ответ со сгенерированным содержимым:{
"id": "resp_1234567890",
"object": "response",
"created_at": 1234567890,
"model": "openai/o4-mini",
"output": [
{
"type": "message",
"id": "msg_abc123",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "The meaning of life is a philosophical question that has been pondered for centuries...",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 45,
"total_tokens": 57
},
"status": "completed"
}
Потоковая передача ответов
Включите потоковую передачу для генерации ответов в реальном времени:const response = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: 'Write a short story about AI',
stream: true,
max_output_tokens: 9000,
}),
});
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const data = line.slice(6);
if (data === '[DONE]') return;
try {
const parsed = JSON.parse(data);
console.log(parsed);
} catch (e) {
// Skip invalid JSON
}
}
}
}
import requests
import json
response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': 'Write a short story about AI',
'stream': True,
'max_output_tokens': 9000,
},
stream=True
)
for line in response.iter_lines():
if line:
line_str = line.decode('utf-8')
if line_str.startswith('data: '):
data = line_str[6:]
if data == '[DONE]':
break
try:
parsed = json.loads(data)
print(parsed)
except json.JSONDecodeError:
continue
Пример потокового вывода
Потоковый ответ возвращает фрагменты событий, отправленных сервером (SSE):data: {"type":"response.created","response":{"id":"resp_1234567890","object":"response","status":"in_progress"}}
data: {"type":"response.output_item.added","response_id":"resp_1234567890","output_index":0,"item":{"type":"message","id":"msg_abc123","role":"assistant","status":"in_progress","content":[]}}
data: {"type":"response.content_part.added","response_id":"resp_1234567890","output_index":0,"content_index":0,"part":{"type":"output_text","text":""}}
data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":"Once"}
data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" upon"}
data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" a"}
data: {"type":"response.content_part.delta","response_id":"resp_1234567890","output_index":0,"content_index":0,"delta":" time"}
data: {"type":"response.output_item.done","response_id":"resp_1234567890","output_index":0,"item":{"type":"message","id":"msg_abc123","role":"assistant","status":"completed","content":[{"type":"output_text","text":"Once upon a time, in a world where artificial intelligence had become as common as smartphones..."}]}}
data: {"type":"response.done","response":{"id":"resp_1234567890","object":"response","status":"completed","usage":{"input_tokens":12,"output_tokens":45,"total_tokens":57}}}
data: [DONE]
Общие параметры
| Параметр | Тип | Описание |
|---|---|---|
model | строка | Обязательно. Используемая модель (например, openai/o4-mini) |
input | строка или массив | Обязательный. Массив текста или сообщений |
stream | логическое | Включить потоковую передачу ответов (по умолчанию: false) |
max_output_tokens | целое число | Максимальное количество токенов для генерации |
temperature | номер | Температура отбора проб (0-2) |
top_p | номер | Параметр выборки ядра (0-1) |
Обработка ошибок
Грамотно обрабатывайте типичные ошибки:try {
const response = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: 'Hello, world!',
}),
});
if (!response.ok) {
const error = await response.json();
console.error('API Error:', error.error.message);
return;
}
const result = await response.json();
console.log(result);
} catch (error) {
console.error('Network Error:', error);
}
import requests
try:
response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': 'Hello, world!',
}
)
if response.status_code != 200:
error = response.json()
print(f"API Error: {error['error']['message']}")
else:
result = response.json()
print(result)
except requests.RequestException as e:
print(f"Network Error: {e}")
Разговоры с несколькими ходами
Поскольку Responses API не сохраняет состояние, вы должны включать полную историю разговоров в каждый запрос, чтобы сохранить контекст. Параметры состояния, такие какstore: true и Параметры previous_response_id не поддерживаются и отклоняются с 400 ошибка:
// First request
const firstResponse = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: [
{
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'What is the capital of France?',
},
],
},
],
max_output_tokens: 9000,
}),
});
const firstResult = await firstResponse.json();
// Second request - include previous conversation
const secondResponse = await fetch('https://api.llmstore.ru/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'openai/o4-mini',
input: [
{
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'What is the capital of France?',
},
],
},
{
type: 'message',
role: 'assistant',
id: 'msg_abc123',
status: 'completed',
content: [
{
type: 'output_text',
text: 'The capital of France is Paris.',
annotations: []
}
]
},
{
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'What is the population of that city?',
},
],
},
],
max_output_tokens: 9000,
}),
});
const secondResult = await secondResponse.json();
import requests
# First request
first_response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': [
{
'type': 'message',
'role': 'user',
'content': [
{
'type': 'input_text',
'text': 'What is the capital of France?',
},
],
},
],
'max_output_tokens': 9000,
}
)
first_result = first_response.json()
# Second request - include previous conversation
second_response = requests.post(
'https://api.llmstore.ru/v1/responses',
headers={
'Authorization': 'Bearer YOUR_LLMSTORE_API_KEY',
'Content-Type': 'application/json',
},
json={
'model': 'openai/o4-mini',
'input': [
{
'type': 'message',
'role': 'user',
'content': [
{
'type': 'input_text',
'text': 'What is the capital of France?',
},
],
},
{
'type': 'message',
'role': 'assistant',
'id': 'msg_abc123',
'status': 'completed',
'content': [
{
'type': 'output_text',
'text': 'The capital of France is Paris.',
'annotations': []
}
]
},
{
'type': 'message',
'role': 'user',
'content': [
{
'type': 'input_text',
'text': 'What is the population of that city?',
},
],
},
],
'max_output_tokens': 9000,
}
)
second_result = second_response.json()
Обязательные поляПоля
id и Параметры status обязательны для любых assistant ролевые сообщения, включенные в историю разговоров.История разговораВсегда включайте полную историю разговоров в каждый запрос. API не хранит предыдущие сообщения, поэтому контекст необходимо поддерживать на стороне клиента.
Следующие шаги
- Узнайте о Рассуждении возможности
- Исследуйте Вызов инструментов функциональность
- Попробуйте Веб-поиск интеграция