Перейти к основному содержанию
POST
/
api
/
v2
/
generate
Text Generation
curl --request POST \
  --url https://api.example.com/api/v2/generate \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "model": "<string>",
  "messages": [
    {}
  ],
  "stream": true,
  "temperature": 123,
  "max_tokens": 123,
  "system": "<string>"
}
'
{
  "id": "<string>",
  "status": "<string>",
  "model": "<string>",
  "content": "<string>",
  "tokens_used": 123,
  "balance_remaining": 123,
  "usage": {},
  "created_at": "<string>"
}

Request

Authorization
string
обязательно
Bearer token: Authorization: Bearer nb_YOUR_API_KEY
model
string
обязательно
Model slug. See Text Models for all available slugs.Examples: gpt-5, claude-sonnet-4.5, gemini-3-pro, deepseek-r1
messages
array
обязательно
Array of message objects in OpenAI-compatible format.
[
  { "role": "system", "content": "You are a helpful assistant." },
  { "role": "user", "content": "Hello!" }
]
Supported roles: system, user, assistant
stream
boolean
по умолчанию:"false"
Enable server-sent events streaming. See Streaming Guide.
temperature
number
по умолчанию:"0.7"
Sampling temperature between 0.0 and 2.0. Higher values make output more random.
max_tokens
integer
Maximum tokens to generate. Defaults vary by model. Pass null to use model defaults.
system
string
Shorthand for adding a system message. Equivalent to adding { "role": "system", "content": "..." } as the first message.

Request Example

curl -X POST https://neuralbox.top/api/v2/generate \
  -H "Authorization: Bearer nb_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4.5",
    "system": "You are a helpful coding assistant.",
    "messages": [
      { "role": "user", "content": "Write a Python function to parse JSON safely" }
    ],
    "temperature": 0.5
  }'

Response

id
string
Unique generation ID. Use this to retrieve results via GET /generate/status.
status
string
completed | pending | failed
model
string
The model slug used for this generation.
content
string
The generated text.
tokens_used
integer
NeuralBox tokens consumed by this request.
balance_remaining
integer
Your token balance after this request.
usage
object
Raw provider token usage (for reference only, not billed):
{
  "prompt_tokens": 142,
  "completion_tokens": 387,
  "total_tokens": 529
}
created_at
string
ISO 8601 timestamp.

Response Example

{
  "id": "gen_01j9x2abc123",
  "status": "completed",
  "model": "claude-sonnet-4.5",
  "content": "Here's a safe JSON parsing function in Python:\n\n```python\nimport json\nfrom typing import Optional, Any\n\ndef parse_json_safe(text: str) -> Optional[Any]:\n    try:\n        return json.loads(text)\n    except (json.JSONDecodeError, TypeError):\n        return None\n```",
  "tokens_used": 3,
  "balance_remaining": 297,
  "usage": {
    "prompt_tokens": 142,
    "completion_tokens": 387,
    "total_tokens": 529
  },
  "created_at": "2026-03-08T12:00:00Z"
}

Vision (Image Input)

Text models that support vision (gpt-5, claude-sonnet-4.5, gemini-3-pro) accept images in messages:
{
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": { "url": "https://example.com/image.jpg" }
        },
        {
          "type": "text",
          "text": "What's in this image?"
        }
      ]
    }
  ]
}

Multi-turn Conversations

Pass the full conversation history in messages:
{
  "model": "gpt-5",
  "messages": [
    { "role": "user", "content": "My name is Ivan" },
    { "role": "assistant", "content": "Hello Ivan! How can I help you?" },
    { "role": "user", "content": "What's my name?" }
  ]
}
NeuralBox does not store conversation state between requests. You must send the full history each time.