{
  "openapi": "3.0.3",
  "info": {
    "title": "Wicklee Agent API",
    "description": "The evidence layer for self-hosted AI inference. The local agent API served at http://localhost:7700: what is loaded, what will run now, what is wrong and how to verify a fix, over Ollama, vLLM and llama.cpp. There is no hosted service; wicklee.dev serves static files only.",
    "version": "1.0.0",
    "contact": {
      "name": "Wicklee",
      "url": "https://wicklee.dev"
    }
  },
  "servers": [
    {
      "url": "http://localhost:7700",
      "description": "Local agent API (no auth)"
    }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "operationId": "mcpJsonRpc",
        "summary": "MCP JSON-RPC 2.0 endpoint",
        "description": "JSON-RPC 2.0. Tools: get_node_status, get_inference_state, get_active_models, get_metrics_history, wicklee_state, wicklee_readiness, wicklee_inspect. The three wicklee_* tools return the same JSON as GET /v1/state, /v1/readiness and /v1/inspect, calling the same handlers those routes call. get_model_fit and get_observations are retired and answer -32601 with the name of their replacement. fingerprint and verify are deliberately not exposed: they are the only routes that load models. Resources: wicklee://node/metrics, wicklee://node/thermal. Localhost only, no auth required when bound to loopback.",
        "servers": [
          {
            "url": "http://localhost:7700"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": {
                    "type": "string",
                    "enum": [
                      "2.0"
                    ]
                  },
                  "method": {
                    "type": "string"
                  },
                  "params": {
                    "type": "object"
                  },
                  "id": {}
                },
                "required": [
                  "jsonrpc",
                  "method",
                  "id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response"
          }
        }
      }
    },
    "/.well-known/mcp.json": {
      "get": {
        "operationId": "mcpManifest",
        "summary": "MCP server discovery manifest",
        "servers": [
          {
            "url": "http://localhost:7700"
          }
        ],
        "responses": {
          "200": {
            "description": "MCP server manifest with capabilities, tools, and resources"
          }
        }
      }
    },
    "/v1/state": {
      "get": {
        "operationId": "v1State",
        "summary": "What is installed and loaded on this host",
        "description": "Every installed model with its residency, the context it is running at, its measured footprint, how much of it sits outside accelerator memory, and when a real caller last used it. Includes a capability record of which response fields this runtime actually returns, so a caller can tell an unknown from a zero. Localhost agent; no auth when bound to loopback.",
        "responses": {
          "200": {
            "description": "Per-model state and the runtime capability record",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    },
    "/v1/readiness": {
      "get": {
        "operationId": "v1Readiness",
        "summary": "Whether a model can run without displacing another",
        "description": "Call before starting a task. Answers ready_now, requires_loading, would_displace or cannot_determine per model, with the memory headroom and the evidence behind the answer. valid_for_s says how long the answer holds. A requires_loading answer carries coexistence: \"unverified\" whenever another model is resident, meaning it fits by memory accounting only: on the one host measured so far the runtime evicted a resident model in 5 of 6 such cases, so do not treat it as safe.",
        "parameters": [
          {
            "name": "model",
            "in": "query",
            "required": false,
            "description": "One model to answer about. Omit for every installed model.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Readiness per model, or for the one named",
            "content": {
              "application/json": {}
            }
          },
          "404": {
            "description": "The named model is not installed on this host"
          }
        }
      }
    },
    "/v1/inspect": {
      "get": {
        "operationId": "v1Inspect",
        "summary": "Findings about slow or unstable inference, with their evidence",
        "description": "Findings, readiness and what could not be checked, in one answer. Each statement is labelled observed (Wicklee saw it), inferred (a likely cause, always hedged) or verified (measured, with a range), and carries the evidence behind it. A rule that could not run is listed under not_checked rather than silently omitted.",
        "parameters": [
          {
            "name": "since",
            "in": "query",
            "required": false,
            "description": "How far back to look, e.g. 24h, 90m, 7d.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Findings, readiness and not_checked",
            "content": {
              "application/json": {}
            }
          },
          "400": {
            "description": "The since window could not be parsed"
          }
        }
      }
    },
    "/v1/findings": {
      "get": {
        "operationId": "v1Findings",
        "summary": "The findings alone, open or resolved",
        "description": "Resolution is observed rather than scheduled: a finding resolves because an evaluation ran and did not produce it, so resolved_at_ms is when Wicklee last looked and did not see it.",
        "parameters": [
          {
            "name": "all",
            "in": "query",
            "required": false,
            "description": "Include resolved findings.",
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Open findings, or every finding recorded on this node",
            "content": {
              "application/json": {}
            }
          }
        }
      }
    },
    "/v1/receipts": {
      "get": {
        "operationId": "v1ReceiptsList",
        "summary": "Stored per-request measurements",
        "description": "Receipts newest first, with a median and range over the generation rates.",
        "parameters": [
          {
            "name": "model",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipts with decode_tps and prompt_tps per receipt",
            "content": {
              "application/json": {}
            }
          },
          "503": {
            "description": "This agent has no local store, so it keeps no receipts"
          }
        }
      },
      "post": {
        "operationId": "v1ReceiptsPost",
        "summary": "Hand back your runtime's own completion metadata",
        "description": "The preferred way to get exact receipts, and on a default macOS install the only one that works: the proxy cannot bind 11434 while Ollama holds it. Durations are nanoseconds in the runtime's own field names, so the body is a copy of the response object rather than a transformation. Every field is optional except model. A posted receipt also counts as activity for readiness. The route REFUSES any payload containing prompt, response, messages or context with a 400 naming the field: Wicklee stores metadata only, and failing loudly beats quietly dropping a user's text.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "model": "coder:14b",
                "total_duration": 8113331500,
                "load_duration": 6396458,
                "prompt_eval_count": 26,
                "prompt_eval_duration": 130079000,
                "eval_count": 298,
                "eval_duration": 4868000000,
                "num_ctx": 32768
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored, with the receipt and its derived rates",
            "content": {
              "application/json": {}
            }
          },
          "400": {
            "description": "Content field present, model missing, or a duration that is not a number"
          },
          "503": {
            "description": "This agent has no local store, so a receipt cannot be kept"
          }
        }
      }
    },
    "/v1/fingerprint": {
      "post": {
        "operationId": "v1Fingerprint",
        "summary": "A consented test run",
        "description": "The only routes that send inference requests are this one and /v1/verify. Sends a fixed synthetic prompt at a known length, temperature zero and a fixed seed, always passing the model's running num_ctx — omitting it reloads the model at 4096, which would destroy the state being measured. An unknown running context refuses rather than guessing. A body without consent true is answered 400 with the plan and the sentence being agreed to. Not exposed over MCP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "kind": "decode_rate",
                "models": [
                  "coder:14b"
                ],
                "runs": 3,
                "consent": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The run's measurements, with a median and range per model",
            "content": {
              "application/json": {}
            }
          },
          "400": {
            "description": "Consent missing: the body carries the plan and the consent text"
          },
          "409": {
            "description": "Refused by the host — not resident, unknown context, or a model in use"
          },
          "503": {
            "description": "No runtime found, or no local store"
          }
        }
      }
    },
    "/v1/verify": {
      "post": {
        "operationId": "v1Verify",
        "summary": "Re-run a finding's test and compare it with the first run",
        "description": "Run it once for a baseline, change something, run it again. Returns both sides with medians and ranges, what differed in the configuration, and one of improved, worse or no measurable change. A verdict needs non-overlapping ranges, three receipts a side, and medians at least 5% apart; anything else is no measurable change with the reason stated. Not exposed over MCP.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "example": {
                "finding_id": "F-7fff93",
                "consent": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The run, and the comparison when there is a baseline to compare against",
            "content": {
              "application/json": {}
            }
          },
          "400": {
            "description": "Consent missing, or finding_id absent"
          },
          "404": {
            "description": "No such finding on this node"
          },
          "409": {
            "description": "Refused by the host, or the finding names no model to measure"
          },
          "503": {
            "description": "No runtime found, or no local store"
          }
        }
      }
    },
    "/api/sla": {
      "get": {
        "operationId": "getInferenceSla",
        "summary": "Inference SLA Monitor — p50/p95/p99 percentiles",
        "description": "Returns p50/p95/p99/max for TTFT, end-to-end latency, and TPOT computed via DuckDB quantile_cont() over per-request inference_traces. Compliance percentage against a configurable TTFT target, the 20 most-recent violations, and per-model breakdown. Requires the Ollama proxy (Settings → Proxy) to capture per-request data. Window: 1–1440 minutes (24h hard ceiling — that's the trace retention).",
        "servers": [
          {
            "url": "http://localhost:7700"
          }
        ],
        "parameters": [
          {
            "name": "window_min",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 60,
              "minimum": 1,
              "maximum": 1440
            }
          },
          {
            "name": "target_ttft_ms",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 500,
              "minimum": 1
            }
          },
          {
            "name": "model",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional model filter — narrows percentiles to a single model name."
          }
        ],
        "responses": {
          "200": {
            "description": "SLA summary",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SlaSummary"
                }
              }
            }
          }
        }
      }
    },
    "/api/runtime-config": {
      "get": {
        "operationId": "getRuntimeConfig",
        "summary": "Runtime Config Surface (v0.9.0) — cached launch-time config for a model",
        "description": "Returns the cached RuntimeConfig for the named model. Available across Ollama (parsed from /api/show on model change), vLLM (5-min poller, tries /v1/server_info then falls back to ps aux), and llama.cpp (5-min poller, tries /props then falls back to ps aux). Reads in-memory cache only — never blocks on I/O and works regardless of DuckDB store health. Templates and system prompts stay local — the cloud telemetry push does NOT carry these fields.",
        "servers": [
          {
            "url": "http://localhost:7700"
          }
        ],
        "parameters": [
          {
            "name": "model",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "llama3.1:8b"
          }
        ],
        "responses": {
          "200": {
            "description": "Cached RuntimeConfig",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RuntimeConfig"
                }
              }
            }
          },
          "400": {
            "description": "Missing ?model= query param"
          },
          "404": {
            "description": "No cached config for this model yet"
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Agent diagnostic",
        "description": "Agent version, build target, node id, whether the DuckDB store initialised, and which store-gated routes are available.",
        "responses": {
          "200": {
            "description": "Health report",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "agent_version": {
                      "type": "string"
                    },
                    "build_target": {
                      "type": "string"
                    },
                    "node_id": {
                      "type": "string"
                    },
                    "store_healthy": {
                      "type": "boolean"
                    },
                    "routes_available": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "routes_unavailable": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Finding": {
        "type": "object",
        "properties": {
          "node_id": {
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "low",
              "medium",
              "high"
            ]
          },
          "pattern": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "detail": {
            "type": "string"
          },
          "value": {
            "type": "number",
            "format": "float"
          },
          "unit": {
            "type": "string"
          }
        }
      },
      "SlaSummary": {
        "type": "object",
        "properties": {
          "window_minutes": {
            "type": "integer"
          },
          "request_count": {
            "type": "integer"
          },
          "error_count": {
            "type": "integer"
          },
          "error_rate_pct": {
            "type": "number",
            "format": "float"
          },
          "ttft": {
            "$ref": "#/components/schemas/SlaPercentiles"
          },
          "e2e": {
            "$ref": "#/components/schemas/SlaPercentiles"
          },
          "tpot": {
            "$ref": "#/components/schemas/SlaPercentiles"
          },
          "sla": {
            "type": "object",
            "properties": {
              "target_ttft_ms": {
                "type": "integer"
              },
              "compliance_pct": {
                "type": "number",
                "format": "float"
              },
              "violations_count": {
                "type": "integer"
              },
              "violations": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/SlaViolation"
                }
              }
            }
          },
          "by_model": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "model": {
                  "type": "string"
                },
                "count": {
                  "type": "integer"
                },
                "p95_ttft_ms": {
                  "type": "number",
                  "format": "float"
                },
                "p95_e2e_ms": {
                  "type": "number",
                  "format": "float"
                }
              }
            }
          }
        }
      },
      "SlaPercentiles": {
        "type": "object",
        "properties": {
          "p50": {
            "type": "number",
            "format": "float"
          },
          "p95": {
            "type": "number",
            "format": "float"
          },
          "p99": {
            "type": "number",
            "format": "float"
          },
          "max": {
            "type": "number",
            "format": "float"
          }
        }
      },
      "SlaViolation": {
        "type": "object",
        "properties": {
          "ts_ms": {
            "type": "integer",
            "format": "int64"
          },
          "model": {
            "type": "string"
          },
          "ttft_ms": {
            "type": "integer"
          },
          "latency_ms": {
            "type": "integer"
          }
        }
      },
      "RuntimeConfig": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string",
            "example": "llama3.1:8b"
          },
          "runtime": {
            "type": "string",
            "enum": [
              "ollama",
              "vllm",
              "llamacpp"
            ]
          },
          "captured_at_ms": {
            "type": "integer",
            "format": "int64"
          },
          "context_length": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "n_gpu_layers": {
            "type": "integer",
            "nullable": true
          },
          "quantization": {
            "type": "string",
            "nullable": true,
            "example": "Q4_K_M"
          },
          "parameter_count": {
            "type": "integer",
            "format": "int64",
            "nullable": true
          },
          "template": {
            "type": "string",
            "nullable": true,
            "description": "Ollama only. Stays local — never leaves the machine."
          },
          "system_prompt": {
            "type": "string",
            "nullable": true,
            "description": "Ollama only. Stays local — never leaves the machine."
          },
          "process_args": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true,
            "description": "vLLM / llama.cpp — full command-line args."
          },
          "raw": {
            "type": "object",
            "nullable": true,
            "description": "Full raw runtime-introspection response."
          }
        }
      },
      "MetricsPayload": {
        "type": "object",
        "description": "Full telemetry payload. All fields optional (null when unavailable).",
        "properties": {
          "node_id": {
            "type": "string"
          },
          "hostname": {
            "type": "string"
          },
          "inference_state": {
            "type": "string",
            "enum": [
              "live",
              "idle-spd",
              "busy",
              "idle"
            ]
          },
          "thermal_state": {
            "type": "string",
            "enum": [
              "Normal",
              "Fair",
              "Serious",
              "Critical"
            ]
          },
          "thermal_source": {
            "type": "string",
            "enum": [
              "nvml",
              "iokit",
              "coretemp",
              "clock_ratio",
              "sysfs",
              "wmi"
            ]
          },
          "penalty_avg": {
            "type": "number",
            "format": "float"
          },
          "cpu_usage_percent": {
            "type": "number",
            "format": "float"
          },
          "memory_pressure_percent": {
            "type": "number",
            "format": "float"
          },
          "gpu_utilization_percent": {
            "type": "number",
            "format": "float"
          },
          "apple_soc_power_w": {
            "type": "number",
            "format": "float"
          },
          "nvidia_power_draw_w": {
            "type": "number",
            "format": "float"
          },
          "nvidia_gpu_temp_c": {
            "type": "number",
            "format": "float"
          },
          "ollama_running": {
            "type": "boolean"
          },
          "ollama_active_model": {
            "type": "string"
          },
          "ollama_tokens_per_second": {
            "type": "number",
            "format": "float"
          },
          "ollama_ttft_ms": {
            "type": "number",
            "format": "float"
          },
          "vllm_running": {
            "type": "boolean"
          },
          "vllm_model_name": {
            "type": "string"
          },
          "vllm_tokens_per_sec": {
            "type": "number",
            "format": "float"
          },
          "vllm_avg_ttft_ms": {
            "type": "number",
            "format": "float"
          },
          "vllm_requests_waiting": {
            "type": "integer"
          },
          "runtime_config_available": {
            "type": "boolean",
            "description": "v0.9.0+ — true when the agent has at least one cached RuntimeConfig. Fetch via GET /api/runtime-config?model=<name>."
          },
          "agent_version": {
            "type": "string"
          },
          "timestamp_ms": {
            "type": "integer",
            "format": "int64"
          }
        }
      }
    }
  }
}
