Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: API checks

on:
pull_request:
paths: [api/**, web/**, .github/workflows/api.yml]
push:
branches: [main]
paths: [api/**, web/**, .github/workflows/api.yml]

permissions:
contents: read

jobs:
api:
runs-on: ubuntu-24.04
defaults:
run:
working-directory: api
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "24"
cache: npm
cache-dependency-path: api/package-lock.json
- run: npm ci
- run: npm run check
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ When you call a hosted model, you take the provider's word for which model answe

<table>
<tr>
<td width="50%"><a href="https://lucid-computing.github.io/akashi/app/"><img src="docs/images/preview-network.png" alt="Network overview: replies logged, selected by the beacon, proved conformant and deviations proved in the last hour, with live traffic below"></a><br><sub><b>Network</b> · every reply signed and logged before delivery</sub></td>
<td width="50%"><a href="https://lucid-computing.github.io/akashi/app/"><img src="docs/images/preview-sampling.png" alt="The sampling lattice: one cell per logged reply, with the few selected by the beacon shown as filled squares, and a selection recomputed below"></a><br><sub><b>Sampling</b> · one reply in 20, chosen by a public beacon round</sub></td>
<td width="50%"><a href="https://akashi.lucidcomputing.ai/app/"><img src="docs/images/preview-network.png" alt="Network overview: replies logged, selected by the beacon, proved conformant and deviations proved in the last hour, with live traffic below"></a><br><sub><b>Network</b> · every reply signed and logged before delivery</sub></td>
<td width="50%"><a href="https://akashi.lucidcomputing.ai/app/"><img src="docs/images/preview-sampling.png" alt="The sampling lattice: one cell per logged reply, with the few selected by the beacon shown as filled squares, and a selection recomputed below"></a><br><sub><b>Sampling</b> · one reply in 20, chosen by a public beacon round</sub></td>
</tr>
<tr>
<td width="50%"><a href="https://lucid-computing.github.io/akashi/app/"><img src="docs/images/preview-challenge.png" alt="A regulator's challenge moving through filed, admitted, transcript released, proving and verdict signed, ending in a proved deviation"></a><br><sub><b>Challenge</b> · a regulator asks for a proof and a deviation is proved</sub></td>
<td width="50%"><a href="https://lucid-computing.github.io/akashi/app/"><img src="docs/images/preview-verify.png" alt="Offline verification of a bundle with one bit changed: four checks pass, the proof check fails, outcome rejected with exit 20"></a><br><sub><b>Verify</b> · change one bit of a proof and the CPU check rejects it</sub></td>
<td width="50%"><a href="https://akashi.lucidcomputing.ai/app/"><img src="docs/images/preview-challenge.png" alt="A regulator's challenge moving through filed, admitted, transcript released, proving and verdict signed, ending in a proved deviation"></a><br><sub><b>Challenge</b> · a regulator asks for a proof and a deviation is proved</sub></td>
<td width="50%"><a href="https://akashi.lucidcomputing.ai/app/"><img src="docs/images/preview-verify.png" alt="Offline verification of a bundle with one bit changed: four checks pass, the proof check fails, outcome rejected with exit 20"></a><br><sub><b>Verify</b> · change one bit of a proof and the CPU check rejects it</sub></td>
</tr>
</table>

<sub>The [web preview](https://lucid-computing.github.io/akashi/app/) ([source](web/README.md)), with sample data. No model or prover runs behind it.</sub>
<sub>The [web preview](https://akashi.lucidcomputing.ai/app/) ([source](web/README.md)), with sample data. No model or prover runs behind it.</sub>

One real request went through an opaque router to Llama 4 Maverick and came back as `12<|eot|>`. A separate, disconnected CPU accepted the original proof and rejected a copy with one bit changed. [Commands, measurements and evidence](docs/demo/README.md)

Expand Down
4 changes: 4 additions & 0 deletions api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
.wrangler/
worker-configuration.d.ts
.dev.vars
58 changes: 58 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Akashi platform API

One Cloudflare Worker serves the [web preview](../web/README.md) and this API at `akashi.lucidcomputing.ai`. It takes challenges, keeps one proof job per challenged reply in D1, and hands those jobs to the GPU provers. **The provers are mocked for now:** the cron plays two H100s and writes sample outcomes. No proof is generated or checked.

## How it fits

```text
challenger ──POST /challenges──▶ Worker ──▶ D1: challenges, jobs
▲
H100 worker ──claim, then result───┘ (the GPUs pull: they need outbound HTTPS only)
```

- **A challenge** names a logged reply by its `request_id`, with a role (`holder`, `regulator`, `auditor`, `thirdparty`), a reason (`model`, `altered`, `routine`) and an optional public note. The bearer key identifies the challenger and is stored only as its SHA-256.
- **Quotas** are those of [the parameters](../specs/parameters.md#rate-limits): 10 per key per hour and 3 per reply per day. A refusal answers 429 with `Retry-After`.
- **One job per reply.** Every challenge on the same reply shares its proof, so the GPUs prove each reply once. A reply whose proof was unavailable is queued again by its next challenge.
- **Leases.** A GPU claims the oldest job under a lease (`LEASE_MS`) and reports the result with that lease. A lease that runs out returns the job to the queue. After `MAX_ATTEMPTS` the outcome is `unavailable`. Both are deployment choices in `wrangler.jsonc`, not spec values.

A challenge reads `queued`, then `proving` while a GPU holds its job, then `settled` with an `outcome` of `conformant`, `deviation` or `unavailable`.

## Routes

| Route | Who | Does |
| --- | --- | --- |
| `GET /api/v1/challenges?limit=20` | Anyone | The most recent challenges, newest first |
| `GET /api/v1/challenges/:id` | Anyone | One challenge and its proof job |
| `POST /api/v1/challenges` | A challenger, `Authorization: Bearer <key>` | File a challenge: `{request_id, role, reason, note?}` |
| `POST /api/v1/prover/claim` | A GPU, `Authorization: Bearer <PROVER_TOKEN>` | `{worker}`. Returns `{request_id, lease, lease_until}`, or 204 when the queue is empty |
| `POST /api/v1/prover/jobs/:request_id` | A GPU, `Authorization: Bearer <PROVER_TOKEN>` | `{lease, outcome, proof_digest, proof_ms}`. 409 when the lease is no longer current |

## What is not real yet

- **The GPU link.** `src/mock-gpu.ts` stands in for the H100s, through the same claim and complete calls a real worker makes. To use the real machines, run a worker loop on each H100 against the two prover routes, give it `PROVER_TOKEN`, and set `MOCK_GPUS` to `"0"`.
- **The checks.** Intake trusts the `request_id` and the declared role. The real intake verifies the holder's receipt bundle and the challenger's key before admitting anything, and the verdict is signed. That logic lives in the Python [auditor](../auditor/README.md) and [prover](../prover/README.md). The job sent to a GPU carries only the `request_id`, not the escrowed transcript.

## Work on it

Node 24.

```sh
cd api
npm ci
npm run check # types, then the tests in the Workers runtime
npm run dev # local D1, the site and the API on http://localhost:8787
```

Put `PROVER_TOKEN=<anything of 16 characters or more>` in `api/.dev.vars` to call the prover routes locally. To run the cron by hand, open `http://localhost:8787/__scheduled?cron=*+*+*+*+*`.

## Deploy

Cloudflare builds and deploys `main` on every push (Workers Builds, connected to this repository). The settings are:

| Setting | Value |
| --- | --- |
| Root directory | `api` |
| Build command | `npm ci` |
| Deploy command | `npm run deploy` (applies new D1 migrations, then deploys) |

The custom domain is declared in `wrangler.jsonc`, so a deploy creates its DNS record in the `lucidcomputing.ai` zone. Set the prover token once with `npx wrangler secret put PROVER_TOKEN`.
29 changes: 29 additions & 0 deletions api/migrations/0001_init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- One proof job per logged reply: every challenge on the same reply shares it.
CREATE TABLE jobs (
request_id TEXT PRIMARY KEY,
state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'leased', 'done')),
created_at INTEGER NOT NULL,
attempts INTEGER NOT NULL DEFAULT 0,
lease TEXT,
worker TEXT,
leased_at INTEGER,
lease_until INTEGER,
outcome TEXT CHECK (outcome IN ('conformant', 'deviation', 'unavailable')),
proof_digest TEXT,
proof_ms INTEGER,
done_at INTEGER
);
CREATE INDEX jobs_queue ON jobs (state, created_at);

CREATE TABLE challenges (
id TEXT PRIMARY KEY,
request_id TEXT NOT NULL, -- the job it shares with every other challenge on this reply
role TEXT NOT NULL CHECK (role IN ('holder', 'regulator', 'auditor', 'thirdparty')),
challenger TEXT NOT NULL, -- SHA-256 of the caller's bearer key, never the key
reason TEXT NOT NULL CHECK (reason IN ('model', 'altered', 'routine')),
note TEXT NOT NULL DEFAULT '', -- public with the verdict
filed_at INTEGER NOT NULL
);
CREATE INDEX challenges_recent ON challenges (filed_at);
CREATE INDEX challenges_by_challenger ON challenges (challenger, filed_at);
CREATE INDEX challenges_by_request ON challenges (request_id, filed_at);
Loading