Spaces:
Paused

miracle / docs /api.md
dushyantsingh0
backend stabilization
9f4dea0
|
Raw History Blame Contribute Delete
10.3 kB

API Reference

Base URL (production): https://3scerror404-nexus.hf.space
Base URL (local dev): http://localhost:8000
Interactive docs: {base}/docs (Swagger UI), {base}/redoc

All endpoints require Authorization: Bearer <access_token> unless marked public.


Authentication (/api/v1/auth)

POST /api/v1/auth/register/

Public. Create a new user account. If the workspace does not exist, it is provisioned automatically along with a local admin account.

Body

{
  "email": "user@example.com",
  "password": "string",
  "full_name": "string",
  "workspace_name": "Acme Corp"
}

Response 201

{
  "id": "uuid",
  "email": "user@example.com",
  "full_name": "string",
  "workspace_id": "uuid",
  "role": "CUSTOMER_USER"
}

POST /api/v1/auth/login/

Public. Exchange credentials for JWT token pair.

Body application/x-www-form-urlencoded

username=user@example.com&password=secret

Response 200

{
  "access_token": "eyJ...",
  "refresh_token": "eyJ...",
  "token_type": "bearer"
}

POST /api/v1/auth/refresh/

Exchange a valid refresh token for a new access token.

Body

{ "refresh_token": "eyJ..." }

Response 200 β€” same shape as /login/.


POST /api/v1/auth/logout/

Revoke the current access token (adds JTI to Redis blocklist).

Response 204 No content.


POST /api/v1/auth/forgot-password/

Public. Send a password-reset email via Resend.

Body { "email": "user@example.com" }

Response 200 { "message": "Reset email sent" }


POST /api/v1/auth/reset-password/

Public. Complete password reset with the token from email.

Body { "token": "string", "new_password": "string" }

Response 200 { "message": "Password updated" }


Tickets (/api/v1/tickets)

GET /api/v1/tickets/

List tickets visible to the current user in their workspace.

Query params

Param Type Description
status string Filter by status enum value
priority string Filter by priority (P0–P3)
category string Filter by category
assigned_to uuid Filter by assignee
search string Full-text keyword search

Response 200 β€” array of ticket objects.


GET /api/v1/tickets/paginated/

Paginated ticket list with the same filters as above.

Query params β€” all filters above, plus:

Param Type Default
page int 1
page_size int 20
sort_by string created_at
sort_dir string desc

Response 200

{
  "items": [...],
  "total": 142,
  "page": 1,
  "page_size": 20,
  "pages": 8
}

GET /api/v1/tickets/search/

Hybrid semantic + keyword search (pgvector + TSVECTOR).

Query params q (required) β€” natural-language query string.

Response 200 β€” ranked array of ticket objects with a score field.


POST /api/v1/tickets/

Create a new ticket. Triggers background AI summarization and embedding jobs.

Body

{
  "title": "string",
  "description": "string",
  "priority": "P1",
  "category": "string",
  "project_id": "uuid"
}

Response 201 β€” full ticket object.


GET /api/v1/tickets/{ticket_id}/

Fetch a single ticket. Field set is role-sanitized (customers omit internal notes).


PUT /api/v1/tickets/{ticket_id}/

Update ticket fields. Partial update β€” only supplied fields are changed.

Body β€” any subset of ticket fields.


PUT /api/v1/tickets/{ticket_id}/status/

Transition ticket status. Enforces valid state machine transitions.

Body { "status": "IN_PROGRESS", "note": "optional string" }

Valid transitions:

OPEN β†’ ACKNOWLEDGED β†’ IN_PROGRESS β†’ RESOLVED β†’ CLOSED
       ↑_____________________|

PUT /api/v1/tickets/{ticket_id}/assign/

Assign ticket to a staff user in the same workspace.

Body { "user_id": "uuid" }


GET /api/v1/tickets/statuses/

Return all valid status enum values.

GET /api/v1/tickets/priorities/

Return all valid priority enum values (P0–P3) with SLA targets.


Messages (/api/v1/tickets/{ticket_id}/messages)

GET /api/v1/tickets/{ticket_id}/messages/

Fetch the message thread for a ticket. Internal messages are filtered out for CUSTOMER_* roles.

Response 200 β€” array of message objects.


POST /api/v1/tickets/{ticket_id}/messages/

Add a message to a ticket thread. Triggers mention notification jobs.

Body

{
  "content": "string",
  "is_internal": false,
  "mentions": ["uuid"]
}

Response 201 β€” message object.


Knowledge Base (/api/v1/kb)

POST /api/v1/kb/

Create a KB article. Triggers background chunking + embedding indexing.

Body

{
  "title": "string",
  "content": "string (markdown)",
  "project_id": "uuid",
  "tags": ["string"]
}

GET /api/v1/kb/

List KB articles for the current workspace. Supports ?project_id=, ?tag=, ?page=.


GET /api/v1/kb/{article_id}/

Fetch a single article including version history.


PUT /api/v1/kb/{article_id}/

Update an article. Creates a new version snapshot before applying changes.


DELETE /api/v1/kb/{article_id}/

Soft-delete an article (sets deleted_at). Removes its chunks from the vector index.


GET /api/v1/kb/search/

Semantic + keyword search across KB chunks.

Query params q (required), project_id (optional), limit (default 10).

Response 200 β€” array of { article, chunk, score } objects.


POST /api/v1/kb/bulk-sync/

Batch import articles from external sources. Deduplicates by content_hash.

Body β€” array of article objects.

Response 202 β€” { "queued": N } β€” each article is indexed asynchronously.


Nexus Master Agent (/api/v1/nexus)

POST /api/v1/nexus/query/

Submit a natural-language query to the Nexus agent. The agent resolves intent, routes to the appropriate sub-node (KB search, ticket ops, analytics, remediation), and returns a structured response.

Body

{
  "message": "What are the top recurring issues this month?",
  "thread_id": "uuid (optional β€” omit to start new thread)"
}

Response 200

{
  "answer": "string",
  "sources": [{ "type": "ticket|kb", "id": "uuid", "title": "string" }],
  "thread_id": "uuid",
  "tokens_used": 420
}

Response fields are RBAC-masked β€” customers receive a narrower answer than staff.


POST /api/v1/nexus/stream/

Streaming variant of /query/. Returns text/event-stream (SSE). Each chunk is a delta string; the final chunk contains sources and thread_id metadata.

Body β€” same as /query/.


GET /api/v1/nexus/threads/{thread_id}/history/

Return the full conversation history for a Nexus thread.

Response 200 β€” array of { role, content, created_at } objects.


Dashboard (/api/v1/dashboard)

GET /api/v1/dashboard/telemetry/

Workspace ticket counts broken down by status, priority, and category for the current period.

Response 200

{
  "by_status": { "OPEN": 14, "IN_PROGRESS": 6, ... },
  "by_priority": { "P0": 2, "P1": 8, ... },
  "by_category": { "Billing": 9, ... },
  "sla_breached": 3,
  "avg_resolution_hours": 4.2
}

GET /api/v1/dashboard/insights/

AI-generated narrative insights for the workspace (generated by the heavy worker every 6 hours).

Response 200 { "insights": "string (markdown)" }


GET /api/v1/dashboard/trends/

Historical ticket volume and resolution time over the past 30 days.

Query params ?days=30 (default), ?granularity=day|week.


Reports (/api/v1/reports)

GET /api/v1/reports/sla-audit/

All SLA breaches in the workspace for a given period.

Query params ?from=ISO8601&to=ISO8601&priority=P0


GET /api/v1/reports/personnel/

Per-agent metrics: tickets handled, avg resolution time, customer satisfaction score.

Roles required: SC_LEAD, SC_ADMIN, SUPERADMIN.


GET /api/v1/reports/sentiment/

Sentiment distribution across ticket messages (positive / neutral / negative).


Notifications (/api/v1/notifications)

GET /api/v1/notifications/

List unread notifications for the current user.

POST /api/v1/notifications/{id}/read/

Mark a notification as read.

POST /api/v1/notifications/read-all/

Mark all notifications as read.


System & admin

GET /api/v1/system/health/

Public. Infrastructure health check.

Response 200

{
  "status": "ok",
  "db": "connected",
  "redis": "connected",
  "arq": "connected",
  "version": "string"
}

GET /api/v1/worker/jobs/

List active ARQ job records. Requires SC_ADMIN or higher.


WebSockets (/ws)

WS /ws/{workspace_id}?token=<access_token>

Subscribe to workspace-level real-time events. The token is validated on connection; invalid or revoked tokens close the socket with code 4001.

Events received (JSON)

{ "type": "ticket.status_changed", "payload": { "ticket_id": "uuid", "new_status": "..." } }
{ "type": "ticket.created",        "payload": { ... } }
{ "type": "sla.breach",            "payload": { "ticket_id": "uuid", "priority": "P0" } }
{ "type": "insight.ready",         "payload": { "summary": "..." } }

WS /ws/tickets/{ticket_id}?token=<access_token>

Subscribe to a single ticket's thread. Fires on new messages and status changes.

Events received

{ "type": "message.created", "payload": { "message_id": "uuid", "content": "..." } }
{ "type": "ticket.assigned",  "payload": { "assignee_id": "uuid" } }

Error responses

All errors follow the RFC 7807 problem format:

{
  "detail": "human-readable message"
}
HTTP code Meaning
400 Validation error or invalid state transition
401 Missing or expired token
403 Role does not have permission
404 Resource not found (workspace-scoped)
409 Conflict (e.g. duplicate content hash)
422 Pydantic schema validation failure
429 Rate limit exceeded
500 Unhandled server error (check logs)