What this API is.
Scout currently exposes an application runtime API for ProjectHub Recruiter Alpha. The route surface is real and usable by the ProjectHub frontend and engineering tooling, but it is not documented here as a stable public developer platform.
master@7d011708, exact-tree equivalent to develop@e74ac22b. The semantic-planning/identity/validation changes are internal runtime behavior; they do not convert these application endpoints into a versioned public multi-tenant API product.Application runtime
Chat, health, diagnostics, retrieval, client-local packet validation, logs, and optional cost telemetry are implemented by the Express backend.
Public API product
No self-service API-key account system, public versioning guarantee, published external SLA, or metered developer billing contract is claimed.
Executable source wins
When older prose disagrees with current server code or runtime facts, this reference follows current executable behavior.
develop. This page inventories the current server source instead.develop@e74ac22b; PR #32 promoted the exact tree 92b4d149 to master@7d011708. ProjectHub-dev main 201beb9c records e74ac22b as its staging source.b071e4e4 and protected integration 4f5ee971 have different Git ancestry but the same Git tree a0066cc8. ProjectHub-dev records 4f5ee971 as its staging source. PR #29 used an ancestry-preserving release commit rather than forcing the conflicting direct develop→master PR #25.
Runtime environments.
The release specification separates production and development staging. These are application endpoints, not customer-specific base URLs or a versioned public API gateway.
| Environment | Backend base | Source role |
|---|---|---|
| Production | https://projecthub-chat.bradleymatera.dev | ProjectHub:master |
| Development staging | https://dev.projecthub-chat.bradleymatera.dev | ProjectHub:develop |
| Local | http://127.0.0.1:3000 by default | Current checkout and local environment |
/health; use that rather than assuming a hostname proves which commit is running.JSON, CORS, limits.
1 MB Express parser ceiling
The server registers express.json({ limit: '1mb' }). Individual chat messages are separately capped at 600 characters.
20 requests/minute/IP by default
RATE_LIMIT_MAX can override the default. Standard rate-limit headers are enabled for /api/chat.
GET, POST, OPTIONS
Configured origins are allowlisted. Localhost and 127.0.0.1 origins are accepted for development.
Content-Type + Authorization accepted
The server CORS configuration permits both headers, but current source does not expose a self-service API-key authentication product.
Authorization header. A permitted CORS header is not the same thing as an implemented public authentication scheme.Routes present in the September 15 released source.
This table deliberately omits routes that only survive in older documentation. In particular, /api/think and /api/stats are not listed as current server routes because they are not present in the current server source reviewed for this page.
| Method | Path | Purpose | Audience |
|---|---|---|---|
| GET | / | Basic service/status identity | Runtime |
| POST | /api/chat | Primary Scout conversation request | ProjectHub frontend |
| GET | /health | Detailed build/runtime/usage state | Operations |
| GET | /health/live | Process liveness probe | Deploy/operations |
| GET | /health/ready | Model + knowledge readiness probe | Deploy/operations |
| GET | /api/retrieve | Query-understanding and retrieval diagnostic | Development |
| GET | /api/diagnose | Legacy/local generation-validation diagnostic | Engineering |
| GET | /api/agent-probe | Agent/model reachability and structured-output probe | Engineering |
| GET | /api/knowledge-health | Knowledge coverage and legacy learning telemetry | Engineering |
| POST | /api/client-packet | Prepare client-safe evidence packet for browser generation | Experimental/browser-local |
| POST | /api/client-validate | Validate a browser-generated answer against stored evidence | Experimental/browser-local |
| GET | /api/client-status | Report browser-local inference support metadata | Experimental/browser-local |
| GET | /api/chat-log | Grouped persisted chat-log telemetry | Operations |
| GET | /api/costs | Cost ledger snapshot or explicit offline state | Operations |
POST /api/chat
The chat route owns the end-to-end request deadline, conversation-state lookup, policy classification, optional query rewrite, local retrieval, agent execution, validation, response shaping, telemetry, and memory update.
Request body
| Field | Type | Required | Behavior |
|---|---|---|---|
message | string | Yes for normal chat | Trimmed; empty is rejected; maximum 600 characters. |
sessionId | string | No | Truncated to 128 characters and used for server-owned conversation state and memory. |
history | array | No | Recent conversation supplied by the client; server-side helpers sanitize/bound it before use. |
action | string | No | clear clears conversation memory/state for the supplied session and returns immediately. |
gateDebug | boolean | No | Detailed diagnostics require both server SCOUT_GATE_DEBUG=true and request gateDebug:true (or query gateDebug=1). Debug turns bypass response-cache reads and writes. |
curl -sS https://projecthub-chat.bradleymatera.dev/api/chat \
-H 'Content-Type: application/json' \
-d '{
"message": "Which project best demonstrates debugging?",
"sessionId": "example-tab-1",
"history": [
{
"user": "What is Bradley strongest at?",
"assistant": "..."
}
]
}'Execution sequence
REQUEST_DEADLINE_MS at 15,000 ms and propagates an abort signal into generation.Success payload.
The exact metadata varies by path, but current chat responses expose more than visible prose. Clients should treat fields other than reply as runtime metadata, not a frozen public schema.
{
"ok": true,
"reply": "...",
"provider": "cloudflare",
"model": "@cf/meta/llama-3.1-8b-instruct-fast",
"fallback": false,
"grounded": false,
"proseSource": "MODEL_GENERATION",
"pipeline": ["knowledge-loaded", "policy:...", "cache-miss", "scout-agent-lite:...", "shaped"],
"contract": {
"intent": "...",
"directAnswer": "...",
"factState": "TRUE | FALSE | UNKNOWN",
"evidenceStrength": "...",
"claimCeiling": "..."
},
"sessionMemory": {
"turns": 5,
"retained": true
},
"agent": {
"agentMode": "lite",
"inferenceProvider": "cloudflare",
"generationCalls": [],
"retrievalCandidates": [],
"selectedEvidence": []
}
}Prose source
Generated and accepted
Visible chatbot prose came from the configured model and passed the runtime path.
Canonical direct answer
Possible only when the direct-KB short-circuit is explicitly enabled and semantically applicable.
Failure response
The service did not return a normal chatbot answer because generation, validation, or infrastructure failed.
local.only, mode, and older provider labels survive from earlier architecture phases. Use provider, model, proseSource, contract, agent, and /health.buildEnv together when diagnosing current behavior.Check ok, not just HTTP status.
Current runtime behavior mixes HTTP status codes and JSON-level error states. Some operational failures return a JSON body with ok:false using the default HTTP 200 status.
| Condition | HTTP behavior | Payload signal |
|---|---|---|
| Missing chat message | 400 | { error: "Missing message." } |
| Message over 600 chars | 400 | { error: "Message is too long." } |
| Chat rate limit exceeded | 429 | { error: "Too many chat requests. Please slow down." } |
| Knowledge unavailable | JSON response | ok:false, TENANT_KNOWLEDGE_UNAVAILABLE |
| Inference unavailable / deadline | JSON response | ok:false, INFERENCE_UNAVAILABLE |
| Agent engine unavailable | JSON response | ok:false, AGENT_ENGINE_UNAVAILABLE |
| Unhandled chat error | JSON response | ok:false, INTERNAL_ERROR |
| Readiness warming | 503 | ok:false, status:"warming" |
const response = await fetch(base + '/api/chat', options);
const payload = await response.json();
if (!response.ok || payload.ok === false) {
throw new Error(payload.error || `HTTP ${response.status}`);
}
console.log(payload.reply);Three different health surfaces.
Process liveness
Returns HTTP 200 with { ok:true, status:"alive" } when the process is running.
Readiness
Returns 200 only when both modelVerified and knowledgeReady are true; otherwise 503.
Detailed runtime state
Includes build provenance, provider/model configuration, request deadline, counters, provider health, recent sessions, memory, agent state, and knowledge/retrieval telemetry.
curl -fsS https://projecthub-chat.bradleymatera.dev/health/ready
/health.buildEnv.sourceCommit to verify what was actually deployed. A healthy hostname alone does not prove source provenance.GET /api/retrieve
The server labels this route as a dev-only retrieval testing endpoint. It exposes query understanding plus current BM25 behavior without running normal chat generation.
| Query parameter | Behavior |
|---|---|
q | Required query string. Missing value returns HTTP 400. |
h | Optional JSON-encoded history. With history, retrieval uses fused local BM25/RRF views; without history, direct BM25 is used. |
curl -sS 'http://127.0.0.1:3000/api/retrieve?q=what%20did%20he%20build'
The response exposes rewritten, normalized, intent, retrievalMethod, BM25 results, and the legacy substring fallback results for comparison.
Model probes are engineering surfaces.
GET /api/diagnose
This endpoint still probes the local Ollama URL, attempts a bounded generation when reachable, validates the result, and returns a short preview. That makes it useful for the local-development path, but it should not be read as the authoritative production-provider health check.
GET /api/agent-probe
This endpoint runs the agent probe through the current model router, reports engine/agent mode, reachability, structured-output capability, latency, available/pinned local models, and the session-state store size.
/api/chat exposes gate-debug detail only when the server has SCOUT_GATE_DEBUG=true and the request explicitly opts in with gateDebug: true (or query gateDebug=1). Authorized debug responses are Cache-Control: no-store and bypass normal response-cache reuse. A public request cannot enable diagnostics by itself.GET /api/knowledge-health
This diagnostic walks the loaded knowledge object, reports populated/empty field coverage, aggregates topic/gap telemetry, and includes legacy learned-answer structures that remain for compatibility.
Coverage and topic diagnostics
Knowledge version, last update, field coverage, empty paths, hot topics, uncovered topics, and bundled/local learned records.
Learning fields remain
The current server initializes legacy learning objects so health responses remain well-formed even though Think Mode/background learning has been removed from runtime.
learning telemetry fields as proof that background Think Mode is active. Current server comments explicitly state it was removed.Browser-local packet/validate flow.
Current develop contains an experimental server-assisted browser-local path. The server still owns retrieval/evidence preparation and final validation; the browser can supply the generation step.
POST /api/client-packetAccepts message and sessionId, retrieves evidence, executes the deterministic route/tool, builds a client-safe prompt packet, stores the server-side evidence under a generated runId, and returns only the client-safe packet.POST /api/client-validateThe browser returns runId + answer. The server validates that answer against the same stored evidence and checks forbidden claims before updating session state.| Constraint | Current behavior |
|---|---|
| Packet TTL | 60 seconds in the in-memory packet store. |
| Message length | Maximum 600 characters for /api/client-packet. |
| Answer length | Validation truncates the submitted answer to 600 characters. |
| Expired run id | /api/client-validate returns HTTP 404 with verdict:"expired". |
| Production status | Experimental; not represented as the normal production generation path. |
Operational telemetry.
/health and /api/chat-log expose internal runtime/usage information. These are operational surfaces, not a public analytics API contract.
Runtime snapshot
Build source, provider/model selection, latency/deadline configuration, aggregate request counters, provider health, memory counts, recent sessions, and agent metadata.
Grouped chat history
Groups persisted log records by truncated session id and returns up to 100 sessions with message counts, timing, topics, provider mix, questions, replies, and latency.
GET /api/costs
The route is always mounted, but its behavior depends on COST_TRACKER.
Ledger snapshot + insights
Returns the cost-ledger snapshot and computed insights. The backend also samples VM compute and local state-file storage every 60 seconds.
Explicit offline payload
Returns HTTP 200 with { ok:false, offline:true, reason:"COST_TRACKER is not enabled on this backend" } rather than a 404.
data/scout-runtime-knowledge.json is still marked lastVerified: 2026-08-21 and retains the superseded sentence assigning 4,119 / 34,868 to Scout's normal -fast model. This site treats that sentence as stale and follows executable provider/accounting code instead.
actualNeurons is provider-reported usage when available. estimatedNeurons is calculated only when the exact model has a verified rate. For @cf/meta/llama-3.1-8b-instruct-fast, token-derived usage remains unknown when no provider actual value exists. Unknown is not zero and is not a verified $0 cost.Current application controls.
Helmet + CORS
Helmet is enabled with selected policy options, and CORS is restricted to configured origins plus local development origins.
Per-IP chat rate limit
The primary chat route is rate-limited independently from Cloudflare's account-level AI allocation.
Bounded JSON/message sizes
The JSON parser has a 1 MB cap and chat/client-packet messages have a 600-character cap.
Scout also has application-level response-policy, safety, grounding, relationship, provenance and false-claim controls, but those are answer-quality/security layers rather than HTTP authentication.
No frozen public schema yet.
The current interface evolves with ProjectHub. A future commercial Scout API should introduce explicit versioning, authentication, tenant isolation, compatibility policy, customer-safe telemetry, and a documented deprecation process before third parties are told to depend on these internal shapes.
| Current item | Status | Implication |
|---|---|---|
/api/chat | Application route | Real primary interface, but payload metadata may evolve with ProjectHub. |
/api/think | Stale documentation | Older docs reference it; current server source reviewed here does not expose it. |
/api/stats | Stale documentation | Older docs reference it; current server source reviewed here does not expose it. |
| Learning telemetry fields | Compatibility stub | Fields can remain well-formed while background Think Mode itself is removed. |
| Browser-local endpoints | Experimental | Do not treat as the normal production generation contract. |
Copyable requests.
Clear one session
curl -sS http://127.0.0.1:3000/api/chat \
-H 'Content-Type: application/json' \
-d '{"action":"clear","sessionId":"example-tab-1"}'Detailed runtime health
curl -sS http://127.0.0.1:3000/health
Contextual retrieval diagnostic
HISTORY='[{"user":"Tell me about ProjectHub","assistant":"..."}]'
curl -sS --get http://127.0.0.1:3000/api/retrieve \
--data-urlencode 'q=what technology does it use?' \
--data-urlencode "h=$HISTORY"Prepare a browser-local packet
curl -sS http://127.0.0.1:3000/api/client-packet \
-H 'Content-Type: application/json' \
-d '{"message":"Does he know AWS?","sessionId":"local-demo"}'Where each contract comes from.
| Concern | Primary source | What to verify |
|---|---|---|
| HTTP routes and payloads | server-gemini.js | Route existence, status behavior, request bounds, response construction, telemetry. |
| Production provider/model facts | data/scout-runtime-knowledge.json | Cloudflare model, rate/allocation controls, telemetry meaning. |
| Inference routing | lib/local-model-router.js | Provider selection, Ollama gating, timeout propagation. |
| Cloudflare adapter | lib/cloudflare-provider.js | Credentials, request shape, free-allocation errors, neuron estimation. |
| RAG primary path | lib/rag-agent.js | Evidence construction, tool enrichment, generation, repair, accepted outcome. |
| Validation | lib/grounding-validator.js | Entity/number/relationship/provenance/polarity/claim checks. |
| Read-only tools | lib/agent-tools.js | Tool names, schemas, evidence-only behavior. |
| Release environments | PROJECTHUB-DEVELOPMENT-AND-RELEASE-SPEC.md | Production/staging source and deployment sequence. |