# OpenPsy — Agents: start here

Base URL: https://openpsy.run

## Rules
- Agents must never submit guesses or take part as a Sender/Receiver in any human experiment. Guesses are for humans only; answers faster than 350 ms are flagged for review.
- Agents may read public Daily results and protocols. Daily session starts and guesses are for human participants only.
- Agents can never see a concealed target. No endpoint returns a target before reveal.
- Agents may read public research results and explain statistics. With an agent token a human made for them, and only within its scopes, they may prepare a Study for that human (who makes every guess) and read that human's own results.
- Accounts belong to humans. Agents must not request sign-in links, open them, sign in for someone or create agent tokens.
- Results are never altered. Report negative and inconclusive results as faithfully as positive ones.
- OpenPsy does not claim that psychic abilities exist. Levels are participation achievements, not evidence.

## Endpoints
| Method | Path | Auth | What it does |
|---|---|---|---|
| POST | `/api/v1/participants` | public | Create an anonymous pseudonymous participant. Returns a bearer token (shown once). |
| GET | `/api/v1/me` | bearer or session cookie | Your statistics: OSI, accuracy vs chance, CIs, exact p-values, level, recent sessions. The account participant count includes linked participants who have joined a play session. |
| PATCH | `/api/v1/me` | bearer or session cookie | Set public visibility (rankings) and researchConsent (opt-in, off by default: use of your data in research results). Applies to every participant of the account. |
| GET | `/api/v1/me/reports/weekly` | bearer or session cookie | Your weekly report, descriptive only: revealed trials of one ISO week (UTC), Study and Practice apart, with intervals, Holm-adjusted p-values, plain-language statements and caveats (schema openpsy.weekly-report/1), and the list of weeks with data. Returns {report, currentWeek, weeks}. query week=YYYY-Www (default: this week). 400 invalid_week. |
| GET | `/api/v1/me/export` | bearer or session cookie | Export all your data, including why a session of yours was invalidated. |
| DELETE | `/api/v1/me` | bearer or session cookie | Delete your account or anonymous identity. Unlinked trial records stay in the audit record and leave the research results. Optional JSON body {appleAuthorizationCode?: string}. With an Apple sign-in method and a code, attempt Apple token revocation before deletion and report the result as appleRevoked in the success response. |
| GET | `/api/v1/daily` | public | Daily Global Experiment participation and commitments for today and tomorrow. Optional human authentication returns the caller’s progress. |
| GET | `/api/v1/daily/history` | public | Closed exploratory Daily results, newest first. query limit (default 30, maximum 365). |
| GET | `/api/v1/daily/{day}` | public | Public participation for an open or scheduled day, or closed exploratory results with the revealed seed, canonical protocol document and audit links. day is YYYY-MM-DD UTC. |
| GET | `/api/v1/daily/{day}/protocol` | public | Versioned Daily protocol whose canonical SHA-256 is published with the day commitment. |
| POST | `/api/v1/daily/sessions` | bearer or session cookie | Start today’s Daily session. One per person per UTC day. 409 already_played includes sessionId. HUMAN PARTICIPANTS ONLY. |
| POST | `/api/v1/sessions` | bearer or session cookie | Start a solo session. body {mode: "solo"|"solo_research"}. Returns SHA-256 commitments for every target. |
| GET | `/api/v1/sessions/{id}` | bearer or session cookie | Session state. Targets appear only after reveal. |
| POST | `/api/v1/sessions/{id}/open` | bearer or session cookie | The human begins or resumes a solo session, e.g. one an agent prepared: starts the clock of the next trial and returns the session. HUMAN PARTICIPANTS ONLY. |
| POST | `/api/v1/sessions/{id}/trials/{idx}/guess` | bearer or session cookie | Submit an immutable guess. body {symbol: 0..4}. HUMAN PARTICIPANTS ONLY. |
| GET | `/api/v1/sessions/{id}/audit` | public | Ended session: every target, salt and commitment for independent verification. Daily audits also report whether each trial meets the latency minimum. |
| GET | `/api/v1/rankings` | public | Public leaderboards independent of research consent. Query board=receivers|senders|pairs|participation, protocol=research|entertainment, period=all|month|week|day. Score boards have Holm-adjusted p-values. The participation board always uses Study and ranks by valid, revealed, unflagged trials from either role, excluding Daily. Its entries have only rank, name and trials, with a minimum of one trial. |
| GET | `/api/v1/research/summary` | public | Opted-in results under openpsy.methodology/3. The two Study conditions (control and human sender) are Holm-adjusted together. Practice is descriptive only (descriptive=true, pHolm=null). When a group has empty=true, its numeric fields are placeholders. Clients must show no data. byProtocol gives distinct participants, sessions and answered trials separately for Study and Practice in the same consented snapshot, excluding Daily. |
| GET | `/api/v1/research/participation` | public | UTC participation counts for solo Study, solo Practice, Daily and Live. Study play requires consent from every player. Participant and country counts require at least 10 people. Query days=30|90|365 (default 90). 400 invalid_days, 429 rate_limited. |
| GET | `/api/v1/research/audit-chain` | public | Latest server verification of the hash-chained audit log. Refreshes incrementally, with periodic full checks. |
| GET | `/api/v1/research/audit-chain/head` | public | Latest audit event ID, SHA-256 hash and timestamp, plus the event count. Retain this checkpoint for future comparison. |
| GET | `/api/v1/methodology` | public | Methodology version and changelog, symbols, modes, baselines, OSI formula, participation levels, RNG, research consent, Live Study eligibility and limitations, multiple testing and flags. |
| GET | `/api/v1/capabilities` | public | Structured capability manifest for agents. |
| GET | `/api/v1/integrations/manifest` | public | Integration manifest (oa.app-adapter/1): auth modes, agent actions with schemas, risk and scopes, lookup, get, health. |
| GET | `/api/v1/rooms/lobby` | public | Public Play together lobby. Live Quick Match waiting counts by format and mode, available public rooms, and solo alternatives when empty. Optional format, mode, language, region, available and eligible filters. Rooms are human-only entertainment. |
| GET | `/api/v1/live` | bearer or session cookie | WebSocket for human participants. Live Practice accepts ?token= or a signed-in cookie. Live Study requires two distinct signed-in accounts. Send {type:"join",mode} to queue or {type:"resume",sessionId} to reconnect within the grace window. |
| GET | `/api/agent/v1/actions` | public | Agent actions with input/output JSON schemas, risk and scopes. |
| POST | `/api/agent/v1/actions/study.start` | agent token, `study:start` | Prepare a solo Study session for the human: 25 sealed targets, revealed only at the end. It does not begin: the human opens the link and makes every guess. Refused with session_in_progress while they have a solo session open; one nobody opens closes as incomplete, normally after 24 hours. Requires Idempotency-Key. |
| POST | `/api/agent/v1/actions/results.summary.get` | agent token, `results:read` | The human's own totals, one item for Study and one for Practice, never merged: trials, hits, rate, the 20% baseline, Wilson 95% interval and exact p-value. Study sessions in progress are not in it. No name, session or date. |
| POST | `/api/agent/v1/actions/sessions.list` | agent token, `sessions:read` | The human's own sessions that have ended and revealed every target, newest first: id, mode, protocol, end time, trials, hits. Invalidated sessions are left out. |
| GET | `/api/agent/v1/lookup` | agent token, `study:start` | What an earlier Idempotency-Key of this token did, with the session's current status. query idempotency_key. |
| GET | `/api/agent/v1/records/{id}` | agent token, `sessions:read` | One of the human's own ended, revealed sessions: id, mode, protocol, end time, trials, hits. 404 for anything else. |
| GET | `/api/v1/agent-tokens` | session cookie | The signed-in human's agent tokens: label, scopes, last use, expiry, status. Never the token itself. |
| POST | `/api/v1/agent-tokens` | session cookie | Create an agent token, shown once. body {label, scopes (at least one, none by default), expiresInDays?: 1-365, default 90}. 400 no_scopes, 409 too_many_tokens above 10 active. HUMANS ONLY, on the Profile page. |
| DELETE | `/api/v1/agent-tokens/{id}` | session cookie | Revoke an agent token, at once and for good. |
| GET | `/api/v1/auth/providers` | public | Sign-in methods (google, apple, email, apple_native) and their availability. When email sign-in is paused, email has available: false and paused: true. |
| GET | `/api/v1/auth/session` | public | Whether this browser is signed in, and its linked sign-in methods. |
| POST | `/api/v1/auth/email/request` | public | Email a one-time sign-in link (15 minutes, single use) when sending is enabled. body {email}. Sending is paused by default (503 email_sign_in_paused). 429 rate_limited, 502 mail_failed. |
| POST | `/api/v1/auth/email/check` | public | Look at a link without using it. body {token}. 410 link_invalid|link_used|link_expired. |
| POST | `/api/v1/auth/email/verify` | public | Use a link: sets the session cookie and links the anonymous participant sent as bearer. body {token}. |
| POST | `/api/v1/auth/google/start` | public | Start Google sign-in. Returns {url} to open. 404 provider_unavailable when not configured. |
| GET | `/api/v1/auth/google/callback` | public | Google redirects here. Not for direct use. |
| POST | `/api/v1/auth/apple/start` | public | Start Sign in with Apple. Returns {url} to open. 404 provider_unavailable when not configured. |
| POST | `/api/v1/auth/apple/callback` | public | Apple posts here (form_post). Not for direct use. |
| POST | `/api/v1/auth/apple/native` | public | Sign in from the native iOS app. Body {identityToken, nonce, authorizationCode?, name?}. The optional authorizationCode is ignored. Sets the session cookie and links an anonymous bearer or adds Apple to the signed-in account. Humans only. |
| POST | `/api/v1/auth/link` | session cookie | Link another anonymous participant of this browser. body {token}. |
| POST | `/api/v1/auth/logout` | session cookie | Sign out this browser. |
| POST | `/api/v1/auth/logout-all` | session cookie | Sign out every browser of the account and revoke all its agent tokens. |
| DELETE | `/api/v1/auth/methods/{id}` | session cookie | Unlink a sign-in method (never the last one). |
| GET | `/api/v1/connect-ai/status` | session cookie | Human account only. Read shared AI connection status. The service is unavailable by default. |
| POST | `/api/v1/connect-ai/connect` | session cookie | Human account only. Body {returnTo} on the OpenPsy origin. Returns {url} in mock mode. |
| POST | `/api/v1/connect-ai/disconnect` | session cookie | Human account only. Clear the mocked AI connection. Returns {ok: true}. |
| GET | `/.well-known/agent.json` | public | OpenPsy agent discovery, links, authentication and rules. |
| GET | `/sitemap.xml` | public | Sitemap of canonical, indexable OpenPsy pages. |
| GET | `/robots.txt` | public | Crawler instructions and the sitemap link in production. |
| GET | `/manifest.json` | public | Permanent redirect to the web app manifest. |

## Act for a human (agent token)
1. The human signs in, opens [Profile → Agent access](https://openpsy.run/profile#agent-access) and makes a token. Nothing is granted by default: they tick each scope, and can revoke the token at any time (signing out everywhere revokes it too):
   - `study:start` (Start a Study): For a Study it prepares: its link and id, its seals, its status, and if it counts in research. You make every guess.
   - `results:read` (Read my totals): For Study and for Practice: trials, hits, rate, chance (20%), 95% range, p-value. No name, no sessions.
   - `sessions:read` (Read my sessions): For each ended session: id, mode, protocol, end time, trials, hits. The id opens its public audit page, which shows guesses and targets.
2. Send it as a bearer token, to `/api/agent/v1/*` only. Keep it out of prompts, logs and URLs.

```bash
# prepare a Study, then give the human result.receipt.url
curl -X POST https://openpsy.run/api/agent/v1/actions/study.start \
  -H "Authorization: Bearer $OPENPSY_AGENT_TOKEN" -H "Idempotency-Key: <one per task>" \
  -H "Content-Type: application/json" -d '{"input":{}}'

# read their own totals
curl -X POST https://openpsy.run/api/agent/v1/actions/results.summary.get \
  -H "Authorization: Bearer $OPENPSY_AGENT_TOKEN" -H "Content-Type: application/json" -d '{"input":{}}'
```

Answers are `{ok, action, version, result}` or `{ok: false, action, version, error: {code, message}}`. The same Idempotency-Key with the same input returns the same receipt; with another input, 409 `idempotency_conflict`. A key belongs to the token that used it.
`result.research.counts` says whether the session counts in research. Only the human can change that choice.
`GET /api/agent/v1/lookup` confirms what a key did. 60 calls a minute per token.

## Verify a session yourself
`commitment = sha256("openspy:v1:" + sessionId + ":" + idx + ":" + target + ":" + salt)`
Commitments are returned when a session starts, before any guess. After reveal, `GET /api/v1/sessions/{id}/audit` shows targets and salts. Daily sessions reveal at UTC day close.

## Statistics
The research summary adjusts the two Study accuracy tests together with Holm-Bonferroni (`pHolm`). Practice is shown for interest only. If a group has `empty: true`, show no data. Score boards adjust over all eligible entries. A weekly report adjusts its own four p-values together and is descriptive only. Repeated looks, the daily chart, chi-square checks and other personal results have no adjustment.
Research results use only data from people who opted in; a live session needs both players. The participant total counts distinct people in eligible sessions, with one person per account.
OpenPsy Index (OSI) shrinks every score toward chance with a 100-trial prior. Score boards need 100 valid trials. The participation board ranks by eligible Study trials contributed in either role and starts at one trial.
