A practical integration guide for developers building server-side applications that call the Neural Hiive® platform API. Covers authentication, request fields, response shapes, session management, and error handling.
The Neural Hiive® Public API gives developers programmatic access to the Neural Hiive platform. It accepts natural-language questions and returns a generated answer, source references, citation metadata, assistant metadata, a session ID, and a message ID.
Example environment: http://<your-base-url>. Replace this with
your assigned
Neural Hiive base URL before deploying to production.
POST /v1/chat.session_id so later messages continue the same conversation.All API requests are made over HTTPS to your assigned Neural Hiive base URL. The two available endpoints are listed below.
| Endpoint | Method | Purpose |
|---|---|---|
/health |
GET | Check whether the API is available. Expected response: {"status":"ok"}. |
/v1/chat |
POST | Send a chat message and receive the complete assistant answer after processing finishes. |
Every request must include an API key and the assigned username. The username is provided by Neural Hiive for each developer or integration; it is not a global fixed value.
Security requirement: Keep the API key on your server. Never put it in browser JavaScript, mobile applications, public repositories, logs, analytics events, or client-visible configuration.
X-API-Key: <your-api-key>
Content-Type: application/json
Authorization: Bearer <your-api-key>
This is the smallest useful request to the platform. Replace the username with the
value Neural Hiive provides for your developer account or integration.
POST http://<your-base-url>/v1/chat
X-API-Key: <your-api-key>
Content-Type: application/json
{
"query": "Generate a table with a list of contracts that are expriring within the next 90 days",
"username": "your-assigned-username@example.com",
"assistant_name": "your-assistant-name",
"session_id": "demo-session-001",
"web_search": false
}
The request body must be a JSON object. Unexpected fields are rejected; keep your request body limited to fields supported by the API.
| Field | Required | Description |
|---|---|---|
query |
Required | The user's visible question or message. |
username |
Required | The username assigned to the developer or integration. This is not a fixed value. The API key and username must match provisioned access. |
assistant_name |
Required | The supported assistant name provisioned for the integration. |
session_id |
Recommended | A stable conversation ID generated by your application. Reuse it for follow-up messages in the same conversation. |
end_user_id |
Optional | Your application's user ID for the person using the chat. |
client_timezone |
Optional | The user's timezone, such as America/Chicago. Useful for time-sensitive answers. |
client_time |
Optional | The user's local timestamp, such as 2026-05-28T10:30:00-05:00. |
added_context |
Optional | Extra extracted text for this request. Use this for PDF, Word, or other document text after your application extracts it. |
images |
Optional | Image inputs as data URLs, public image URLs, or objects with a url field. |
web_search |
Optional | Set true only when public web or recent outside information is needed. Defaults to
false.
|
metadata |
Optional | Optional JSON object for your integration metadata. Do not include secrets or unnecessary personal data. |
On success, the API returns HTTP 200 with the following JSON body.
{
"answer": "Response text...",
"references": [
{
"source_id": "source-id",
"chunk_ids": ["chunk-id"],
"knowledgeName": "Knowledge source name",
"displayText": "Display label",
"filename": "source-file.pdf",
"filename_or_url": "source-file.pdf",
"url": null,
"preview_url": null,
"doc_type": "file",
"page_number": 3,
"citation_count": 1,
"snippets": []
}
],
"citations": {
"version": 2,
"provider": "visible_markdown",
"inline_citations": []
},
"assistant": {
"id": "assistant-id",
"name": "your-assistant-name",
"title": "Assistant title",
"llm": "model-name"
},
"session_id": "demo-session-001",
"message_id": "message-id"
}
Each field in the response serves a specific purpose in your UI and data layer.
| Response field | How to use it |
|---|---|
answer |
Render this as the assistant's main response. It may contain Markdown-style text and inline source links. |
references |
Show these beside or below the answer so users can inspect the sources used by the assistant. |
citations |
Use this metadata if your UI renders precise inline citations. Otherwise you can still display references. |
assistant |
Useful for diagnostics, audit logs, and showing which assistant/model handled the request. |
session_id |
Store and reuse this value for follow-up messages in the same conversation. |
message_id |
Store this in logs if you need to map a response to your own records or support tickets. |
Use server-side code for all API calls. This example reads configuration from environment variables and posts the question to the local API. It uses only the Python standard library, with no third-party dependencies required.
import json
import os
import urllib.request
import uuid
base_url = os.getenv("NH_API_URL", "http://<your-base-url>").rstrip("/")
api_key = os.environ["NH_API_KEY"]
username = os.environ["NH_USERNAME"]
payload = {
"query": "Generate a table with a list of contracts that are expriring within the next 90 days",
"username": username,
"assistant_name": os.getenv("NH_ASSISTANT_NAME", "your-assistant-name"),
"session_id": f"my-app-{uuid.uuid4()}",
"web_search": False,
}
request = urllib.request.Request(
f"{base_url}/v1/chat",
data=json.dumps(payload).encode("utf-8"),
headers={
"X-API-Key": api_key,
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(request, timeout=120) as response:
result = json.loads(response.read().decode("utf-8"))
print(result["answer"])
print(result["references"])
Use this from a backend/server environment only; never directly from browser JavaScript, as that would expose your API key.
const response = await fetch(`${process.env.NH_API_URL}/v1/chat`, {
method: "POST",
headers: {
"X-API-Key": process.env.NH_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
query: "Generate a table with a list of contracts that are expriring within the next 90 days",
username: process.env.NH_USERNAME,
assistant_name: "your-assistant-name",
session_id: "demo-session-001",
web_search: false,
}),
});
if (!response.ok) {
const error = await response.json().catch(() => ({}));
throw new Error(error.detail || `Neural Hiive request failed: ${response.status}`);
}
const result = await response.json();
console.log(result.answer);
console.log(result.references);
Store all secrets in environment variables. Never commit API keys or usernames to version control.
NH_API_URL=http://<your-base-url>
NH_API_KEY=<your-api-key>
NH_USERNAME=your-assigned-username@example.com
NH_ASSISTANT_NAME="your-assistant-name"
A typical production integration keeps Neural Hiive API calls on your server. Your frontend sends user messages to your backend, and your backend calls the Neural Hiive API with the stored API key. The Neural Hiive API is never called directly from the browser.
| Step | Your application does this |
|---|---|
| 1. Start chat | Create a new session_id and store it with the chat record. |
| 2. Send message | Send query, username, assistant_name,
session_id, and optional inputs to /v1/chat.
|
| 3. API returns JSON | Store answer, references, citations,
session_id, and message_id.
|
| 4. UI renders response | Show answer first. Show references and source labels near the answer. |
| 5. User follows up | Send only the latest query and the same session_id. Add request-specific
context again if needed. |
Your application can create any stable session_id. Reusing the same session_id
lets the platform continue the conversation without requiring your app to resend the whole chat history.
{
"query": "Summarize this policy.",
"username": "your-assigned-username@example.com",
"assistant_name": "your-assistant-name",
"session_id": "customer-42-chat-1001",
"added_context": "Extracted policy text..."
}
{
"query": "What references did you use?",
"username": "your-assigned-username@example.com",
"assistant_name": "your-assistant-name",
"session_id": "customer-42-chat-1001"
}
The added_context and images fields let you augment requests with external
content that supports the user's question.
added_context for extracted document text that supports the current question.added_context. Extract text first using your
own document processing pipeline.images only when the question depends on a visual input.{"url":"https://example.com/image.png"}.
Set web_search to true only when a question may require public internet
information or recent information outside configured knowledge sources. It is false by
default and applies only to the current request.
{
"query": "What changed in the latest published guidance?",
"username": "your-assigned-username@example.com",
"assistant_name": "your-assistant-name",
"session_id": "guidance-review-1001",
"web_search": true
}
Always handle non-2xx responses before parsing the success object. Error bodies use the following shape:
{
"detail": "Error message"
}
| Status | Meaning | Recommended handling |
|---|---|---|
| 401 | Missing or invalid API key, missing username, or username does not match provisioned access. | Check server configuration. Do not retry repeatedly. |
| 403 | Username exists but lacks access to requested knowledge sources, or user cannot be found. | Escalate access provisioning or show an authorization error. |
| 422 | Invalid request body. | Fix the request payload. Check required fields and unexpected fields. |
| 429 | Rate limit exceeded. | Use the Retry-After header and exponential backoff. |
| 500 | Neural Hiive service configuration error. | Log message_id if present and contact support. |
| 502 | Neural Hiive service unavailable or invalid upstream response. | Retry with backoff. |
| 504 | Neural Hiive service timed out. | Retry with backoff or ask the user to try again. |
Before going live, verify each item in this list. These are the most common sources of integration issues.
session_id per conversation.message_id for supportability and audit trails.Retry-Afterfor 429.
added_context and images before forwarding
them.Ready to integrate? Reach out to sales@neuralhiive.ai to get your API key, assigned username, and production base URL.