# AiCE partner integration — 14 November 2026

## Publisher Network boundary — 22 November 2026
Journals connect only to **CPD.credit**, which owns publisher onboarding/rights checks, canonicalisation, synchronisation and the widget. Journals must not follow the key-creation steps below to connect directly to AiCE. CPD.credit reuses its existing signed network connection; future publisher networks require explicit service approval. Read [the exact additive canonical article v2 contract](./aice-full-article-guide.md#publisher-network-v2--exact-cpdcredit-handoff). Existing learning-platform keys/operations and Endolaser v1 remain compatible; account-owned material scoring is not publisher-network approval.

## What to copy and where
1. Register at `/register`, confirm your email, sign in, then open `/partners`.
2. Enter your website/organisation name and create a key. The secret is shown once. Copy it directly to your receiving website's private server secrets, never into chat, source code, a browser or localStorage.
3. The copied settings match CPD.credit's existing signed consumer:
   - `AICE_PARTNER_BASE_URL`: `https://www.aicecredits.com` (origin only, no API suffix). This is the canonical address and the only one to configure in a live website; the Lovable hosting address is a deployment mirror for checking and must never be saved as the partner base URL.
   - `CPD_REGISTER_PARTNER_CLIENT_ID`: your generated client ID.
   - `CPD_REGISTER_PARTNER_HMAC_SECRET`: your generated signing key.
4. Update/redeploy CPD.credit after changing settings. The current AiCE account-key changes also need publication. An API key alone does not install a consumer, consent flow or logbook in another website.
5. Never overwrite an existing production CPD.credit key casually: links/results are isolated per client. A new client requires fresh consent links; existing linked data does not automatically migrate. Keep existing integration configuration until an approved transition is tested.

The generated key is a server-to-server HMAC signing secret, NOT a browser widget token or Bearer token. Any similar platform can implement this contract. Accounts can create up to five clients; standard self-service access is `records:read`, `links:write`, `events:write`, `calculations:write`. New CPD partners can submit material for calculations without separate scope approval. Material rights permission, signatures, rate limits and client isolation still apply; this access does not grant accreditation or learner-award authority. Disable revokes future requests; replacing a key invalidates its old value. Store the replacement securely before resuming calls.

## Server implementation
Download `aice-partner-client.mjs`, import it only from your server handler and call `requestAiCE({baseUrl, clientId, secret}, operation, payload)`. Read these config values from server secrets at request time. Use your existing signed consumer instead if it already implements this protocol. The helper returns `{result,evidence}` only after authenticating the response; do not send `evidence` or credentials into analytics. It uses a 60-second timeout; an uncertain timeout is not success. Retry the same serialized payload/request ID with a fresh nonce; never change payload under an existing ID. Use a new ID for each logical operation. Poll stored result rather than regenerate after successful preparation.

All operations are POST to `/api/public/partner/v1/{operation}`, JSON, no query string. Standard maximum body: 65,536 UTF-8 bytes (course calculations: 262,144). Required headers: Content-Type, X-AiCE-Client-Id, X-AiCE-Timestamp (Unix seconds within ±300 s), X-AiCE-Nonce (fresh 22–128 alphanumeric/underscore/dash), Idempotency-Key (1–128 `[A-Za-z0-9._:-]`), X-AiCE-Signature (64 lowercase hex).

HMAC-SHA256 request message, joined with newline, no trailing newline:
`AiCE-PARTNER-V1`, `POST`, exact path, timestamp, nonce, client ID, idempotency key, SHA-256 of exact raw JSON bytes.

Successful reply headers: X-AiCE-Response-Timestamp, X-AiCE-Request-Nonce, X-AiCE-Response-Signature. Before parsing or storing, verify timestamp freshness and echoed nonce, then HMAC-SHA256 over newline-joined `AiCE-PARTNER-RESPONSE-V1`, path, response timestamp, request nonce, client ID, SHA-256(raw reply). Errors are not signed results. Do not follow redirects with credentials.

## Guest assessments
For guests without linked accounts, use the existing key and signed evaluations endpoint with `aice-guest-assessment-v1`. See [the exact guest request/response contract](./aice-guest-assessment-guide.md). Passing guests can receive a real non-accredited AiCE assessment certificate after name/email consent capture; linked legacy assessments below remain unchanged.

## Link the learner first (account-linked assessments)
`link-requests` accepts `{subject,state}`. Subject is your opaque learner identifier, 1–128 `[A-Za-z0-9._:-]`; never an email or foreign auth token. State is a fresh unguessable 16–128 alphanumeric/underscore/dash value bound to that learner's browser session. Set a unique `config.idempotencyKey` for this call.

The signed response returns `request_id`, `expires_at`, `consent_path`, `state`. Send the learner to the AiCE origin plus `consent_path`. They sign in and explicitly approve. A repeated creation may return `already_created` with no recoverable consent path; do not silently create a new consent request. `link-status` accepts `{subject,state,request_id}` and returns pending/linked/declined/expired/revoked. Use a fresh idempotency key for each polling request. Only linked subjects can access assessments/results. Do not map accounts by matching emails.

## Learning material in → assessment evidence out
`evaluations` supports `aice-self-directed-v1` and four actions. All include `schema`, `subject`, `request_id`; Idempotency-Key must equal request_id. Identifiers use the subject format above. Unknown fields are rejected. Do not submit private transcripts automatically.

### prepare
- `consent`: `{granted:true,purpose:"evaluate_shared_learning_and_generate_assessment",captured_at:<ISO date with timezone>}`; captured within 24h, max 5min future tolerance.
- `source`: `{text,origin,sha256}`. Text 100–24,000 characters, origin `chatgpt_user_shared` or `user_shared_material`; hash of exact source text, lowercase SHA-256 hex.
- `learning_evidence`: `{declared_active_minutes,activities,reflection}`. Minutes integer 0–60; reflection max 2,000 characters; max 10 activities, each `{description,source_quote,active_minutes}` with description 10–600 characters, exact source_quote 10–500, minutes 0–60.

Returns evaluation_id, analysis (grounded title, summary, 3–5 objectives, educational level, proposed minutes and rationale), ordered questions/options, bank_version, pass_mark 70 and awaiting_answers or insufficient_evidence. Supported time is capped by declared distinct activities, rounded down in six-minute increments: 60 proposed minutes = 10 questions. Chat length alone is not study duration. Correct answers are never returned. Store evaluation_id and displayed bank_version.

### submit
Add `{evaluation_id:<UUID>,bank_version:1,answers:[zero-based option indexes 0–3]}`. Answer count must match the prepared questions. New request_id, different from prepare. One terminal submission per bank. Exact retries return stored evidence; changed answers conflict. Returns score, passed/failed, objectives_achieved, duration analysis, evidence_summary, record_eligible and assessment date. Retakes require explicit new preparation/consent and preserve the previous failure; generation is capped by the existing three-per-day limit.

### result
Add `{evaluation_id:<UUID>}` with a new read request_id. Returns the saved preparation/assessment or processing status. No new grading; only the same linked learner/client may read it.

### certificate
Add `{evaluation_id:<UUID>}`. Only a saved passing, eligible assessment returns `certificate_download` with content_type `application/pdf`, encoding `base64`, filename and content. Verify signed envelope, decode PDF and serve privately to the same learner. Failure/unsubmitted/ineligible requests return 409. This is an evidence copy, not a public award certificate or independent accreditation.

## What CPD.credit stores
Keep credentials in private server secrets, separate from learner records. Save the verified response, evaluation_id, subject-to-local-learner mapping, request_id, bank/policy versions, source hash, consent timestamp/purpose, score, objectives, estimated minutes, evidence summary and provenance returned by the helper. Keep raw source only when necessary under your explicit retention policy; never store answer keys. Store learner evidence/PDF privately with owner-only access and no public URLs. Encrypt retained sensitive data, use audit logging without contents/credentials, honor consent withdrawal and deletion/retention duties. No retention duration is invented here: each operator must approve one before broad intake.

Use local unique constraints on client_id + evaluation_id + terminal request_id to avoid duplicate logbook entries. Preserve failed/retaken versions, don't overwrite failure into pass. Result is signed synchronous handback/polling, not an outbound callback. A self-directed record must remain labelled `AiCE assessed self-directed learning record`, `not_independently_accredited`, with awarded_minutes, earned_cpd_hours, aice_points and knowledge_coins all zero and pilot_price zero. Do not convert study estimates or quiz passes into verified CPD, course VERIFIED status or learner awards. Independent issuer approval remains separate.

## Other operations
- `records` (`records:read`): `{subject,limit?}` (1–100, default 25), signed export of existing linked canonical awards, assessments, completions, points and events; newest-only window, not full pagination.
- Legacy `evaluations` lookup: `{subject,course_id:<UUID>,request_id}` reads an existing course attempt/award, never fabricates a new award.
- `events` (`events:write`): source must remain wire literal `CPD.register`; fields external_event_id, subject, attempt_id, activity_version, activity_hash (SHA-256), submitted_at (ISO), classification (`team_proficiency`, `study_assessment`, `structured_learning`), quiz `{score,pass_mark}` 0–100; optional evidence content_text (max 30,000), content_sha256, reference (max 2,000), claimed_completed_minutes (0–1,200). Idempotency key = external_event_id + ':' + activity_version. Foreign scores remain external/unverified, not AiCE grading authority.
- `revocations` (`events:write`): `{subject,event_id:<UUID>,reason}` (5–500 chars); revokes source event, never silently rewrites historical awards.
- `course-reviews` uses separate `aice-course-review-v1` contract; `course-calculations` uses `aice-course-calculation-v1` and the standard `calculations:write` scope. Do not call these with self-directed payloads. They do not mark a course VERIFIED or award learners.

## Private course and certificate register
Open `/partners`, then **View register** on your connection. Records belong to the stable client ID, not the secret value; replacing the signing key keeps the register. Workload calculations and learner-earned points are separate. Reviews remain content-review evidence, not independent course approval. Existing awards appear only when bound to the partner and the learner still has active consent. No Polygon call, wallet, coin mint or transaction is enabled by this register.

CPD.credit must call `POST /api/public/partner/v1/certificate-receipts` after it actually issues a certificate. Use `events:write` and the same HMAC wrapper, a unique request_id as Idempotency-Key, and strict schema `aice-certificate-receipt-v1`. Accepted fields: request_id, subject (opaque linked learner), certificate_id (opaque issuer reference), certificate_sha256 (lowercase hash of exact issued PDF bytes), issued_at (ISO timestamp), evidence `{kind,id}`. Kind is `self_directed_assessment` with an existing passing evaluation UUID, or `canonical_cpd_award` with an existing reviewer-issued award UUID already bound to this partner. Future dates beyond five minutes are rejected. Never submit a learner name, email, PDF content, API secret or claimed points in this receipt.

AiCE checks consent/client/learner/evidence and stores the reference idempotently. Same request bytes retry to the same receipt; changed request bytes or reused certificate IDs conflict. Signed reply schema `aice-certificate-receipt-result-v1`: receipt_id, request_id, certificate_id, status `stored`, receipt_authority `partner_reported`, learner_points_issued 0, canonical_certificate_issued false, polygon_status `off`. A receipt is the issuer's signed assertion about a PDF hash, not AiCE verification of that PDF's contents or a new award. No automatic historical imports. CPD.credit/HSI still must implement dispatch after genuine issuance; this chat does not change either project.

## Release checks
Confirm a linked consenting learner, prepare genuine shared material, submit both failing and passing test cases, verify signed read, private certificate access, duplicate/conflicting retry, nonce replay, wrong signature, disabled key and cross-client denial. Do not manufacture learning completion to pass QA. 400 = invalid payload, 401 = authentication/signature failure, 403 = linkage/consent denial, 409 = replay/scope/idempotency/ineligible conflict, 413 = too large, 415 = JSON required, 429 = rate limit, 503 = configuration/service unavailable. Do not retry 4xx blindly; preserve IDs and honor rate limits.

This guide documents source behavior, not proof of a completed CPD.credit or HSI learner integration. Publish the new AiCE portal with owner approval, configure the receiving app privately, then run two-app QA. No payment or Knowledge Coin activation is required.
