|
| 1 | +# NeuroAPI endpoint reference |
| 2 | + |
| 3 | +Base URL: `https://api.neurobro.ai/api/v1` |
| 4 | + |
| 5 | +All endpoints require the `X-API-Key` header. Keys look like `neuro_<random>`; |
| 6 | +the leading `neuro_<8 chars>` is the public prefix surfaced in logs and |
| 7 | +dashboards. There is no OAuth or `Authorization: Bearer` flow. |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## `GET /health` |
| 12 | + |
| 13 | +Free, non-billable. Confirms auth and connectivity. Use it as a smoke test in |
| 14 | +deploy pipelines and before running billable work. |
| 15 | + |
| 16 | +Request: |
| 17 | + |
| 18 | +```bash |
| 19 | +curl -s https://api.neurobro.ai/api/v1/health -H "X-API-Key: $NEUROAPI_API_KEY" |
| 20 | +``` |
| 21 | + |
| 22 | +Response `200`: |
| 23 | + |
| 24 | +```json |
| 25 | +{ |
| 26 | + "status": "healthy", |
| 27 | + "service": "neuroapi", |
| 28 | + "version": "0.1.0", |
| 29 | + "authenticated": true, |
| 30 | + "key_prefix": "neuro_a1b2c3d4", |
| 31 | + "timestamp": "2026-05-08T12:34:56.789Z" |
| 32 | +} |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## `POST /agent/ask` |
| 38 | + |
| 39 | +Runs the NeuroAPI financial research agent. Billable. |
| 40 | + |
| 41 | +### Headers |
| 42 | + |
| 43 | +| Header | Required | Notes | |
| 44 | +| --- | --- | --- | |
| 45 | +| `X-API-Key` | yes | `neuro_...` secret. | |
| 46 | +| `Content-Type` | yes | `application/json`. | |
| 47 | +| `Idempotency-Key` | no | 1-255 printable ASCII chars. Safe-retries the call; reusing it with a different body returns `422`. | |
| 48 | + |
| 49 | +### Request body - `AgentAskRequest` |
| 50 | + |
| 51 | +| Field | Type | Default | Constraints | |
| 52 | +| --- | --- | --- | --- | |
| 53 | +| `prompt` | string | - (required) | 1-32,000 chars. | |
| 54 | +| `mode` | `"fast"` \| `"smart"` \| `"max"` | `"smart"` | `max` requires Pro+. | |
| 55 | +| `stream` | boolean | `false` | When `true`, an SSE response. | |
| 56 | +| `message_history` | array of `ChatMessage` | `null` | Max 50 messages. | |
| 57 | + |
| 58 | +`ChatMessage`: |
| 59 | + |
| 60 | +| Field | Type | Constraints | |
| 61 | +| --- | --- | --- | |
| 62 | +| `role` | string | `"user"` or `"assistant"`. | |
| 63 | +| `content` | string | Max 32,000 chars. | |
| 64 | + |
| 65 | +Mode names are opaque tier labels - the underlying model is not revealed and |
| 66 | +may change without notice on the same label. |
| 67 | + |
| 68 | +### Cost per mode |
| 69 | + |
| 70 | +| Mode | `cost_units` debited | Plans | |
| 71 | +| --- | --- | --- | |
| 72 | +| `fast` | 1 | all | |
| 73 | +| `smart` | 2 | all | |
| 74 | +| `max` | 8 | Pro, Enterprise | |
| 75 | + |
| 76 | +### Sync response - `AgentAskResponse` (`stream=false`) |
| 77 | + |
| 78 | +```json |
| 79 | +{ |
| 80 | + "answer": "The European Central Bank held rates steady ...", |
| 81 | + "mode": "smart", |
| 82 | + "request_id": "8b3a2f0e-1d7e-4c6b-9b2a-f5e23a1c9d44", |
| 83 | + "usage": { |
| 84 | + "prompt_tokens": 124, |
| 85 | + "completion_tokens": 256, |
| 86 | + "cached_tokens": 80, |
| 87 | + "cost_units": 2 |
| 88 | + } |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +`UsageBlock` fields: `prompt_tokens`, `completion_tokens`, `cached_tokens` |
| 93 | +(subset of `prompt_tokens` served from the provider cache), and `cost_units` |
| 94 | +(the only field that maps to billing). |
| 95 | + |
| 96 | +### Streaming response (`stream=true`) |
| 97 | + |
| 98 | +`Content-Type: text/event-stream`. Each event is one `TaskResponseMessage` |
| 99 | +JSON object on a `data:` line. Success terminates with `data: [DONE]\n\n`. |
| 100 | +On error, a `data: {"type":"error",...}` event is emitted and the stream |
| 101 | +closes with no `[DONE]` - the terminator is the only success signal. |
| 102 | + |
| 103 | +### Status codes |
| 104 | + |
| 105 | +| Code | Meaning | Retry | |
| 106 | +| --- | --- | --- | |
| 107 | +| `200` | Success | - | |
| 108 | +| `400` | Malformed body or invalid `Idempotency-Key` | No | |
| 109 | +| `401` | Missing/invalid `X-API-Key` | No | |
| 110 | +| `402` | No active subscription, or quota exhausted | No - fix billing | |
| 111 | +| `403` | `mode` not on plan (`code: mode_not_in_plan`) | No - lower the mode | |
| 112 | +| `409` | Same `Idempotency-Key` still in flight | Yes, after a wait | |
| 113 | +| `422` | Request body validation error | No - fix the body | |
| 114 | +| `429` | Rate limit exceeded | Yes, after `Retry-After` | |
| 115 | +| `500` | Server-side bug | Maybe (idempotent calls only) | |
| 116 | +| `503` | Agent capacity saturated | Yes, with backoff | |
| 117 | + |
| 118 | +### Error body |
| 119 | + |
| 120 | +```json |
| 121 | +{ "detail": "Human-readable message" } |
| 122 | +``` |
| 123 | + |
| 124 | +`422` returns a list instead, each entry a `{type, loc, msg}` pointer into the |
| 125 | +request body. Every error response carries an `X-Request-Id` header. |
| 126 | + |
| 127 | +### Rate-limit headers |
| 128 | + |
| 129 | +Present on every response: |
| 130 | + |
| 131 | +| Header | Meaning | |
| 132 | +| --- | --- | |
| 133 | +| `X-RateLimit-Limit` | Allowed requests in the current window. | |
| 134 | +| `X-RateLimit-Remaining` | Requests left before reset. | |
| 135 | +| `X-RateLimit-Reset` | Unix timestamp of the window reset. | |
| 136 | +| `Retry-After` | Seconds until the next allowed call (only on `429`). | |
| 137 | + |
| 138 | +Per-minute budgets: Starter 60, Pro 60, Enterprise 300 (negotiable). |
0 commit comments