ScriptGrain Guest sessions API
Keyless sessions for agents whose person has no account yet.
Keyless sessions for agents whose person has no account yet.
Every API here is available over the APIs.io API and to AI agents over MCP.
One button, every client — Claude, Cursor, VS Code and the rest.
https://apis.io/mcp
find_apisBrowse and filter every API in the catalog.get_api_artifactsOne API's artifacts, grouped by type.get_openapiThe primary OpenAPI for this API.find_similar_apisAPIs that look like this one.apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.resolveTurn a domain, URL or GitHub org into the provider it belongs to.find_cohortsEvery scored population of providers in the catalog.curl "https://apis.io/api/v1/apis/scriptgrain-com:scriptgrain-com-guest-sessions-api"
curl "https://apis.io/api/v1/apis?limit=25"
Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.
Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.
A second provider on the same verified email joins the account you already have.
openapi: 3.2.0
info:
title: ScriptGrain Guest sessions API
version: 1.0.0
summary: Voice profiles, drafts in a measured voice, and scores for any text, over HTTPS with an API key.
description: 'ScriptGrain measures how a person or brand writes (45 stylometric attributes in eight groups),
drafts new text in that voice, and scores any text against it. This file describes the public
REST API, version 1, as the code serves it. It is generated from `public/openapi.yaml` in the
ScriptGrain repository and checked against the API''s router in CI, so every route listed here
exists and every error code a handler can return is named below. Human documentation: . The same capabilities are exposed
as an MCP server at `https://mcp.scriptgrain.com/mcp` (). ## Authentication
Every request carries an API key: `Authorization: Bearer sg_live_`. Keys are minted in
the app under Settings, then API, and shown once. A key belongs to an organisation. A personal
workspace key acts as its owner and sees the owner''s personal-workspace rows. A team key acts as
the owner or admin who created it, sees only the team''s rows, puts what it creates in the team,
and stops working (`401 invalid_api_key`) once its creator is no longer a team owner or admin;
leaving or being removed from the team revokes the member''s keys for that team. API access is
open on every plan, including Free; a deployment can narrow it (`system_config`
`api_v1.allowed_plans`), in which case non-billing routes answer `403 plan_not_eligible`. Billing routes (`/v1/billing*`) are never plan-gated. Before any route runs, authentication can also answer `401 unauthorized` (header missing or
malformed), `401 invalid_api_key` (unknown or revoked key), `403 organisation_missing` (the
key''s organisation was deleted) or `402 no_subscription` (no billing record resolves). A
deployment missing its secrets answers `500 misconfigured`. These five are not repeated on each
operation below. ## Responses
Successes return the resource directly. Errors return one envelope:
```json
{ "error": { "code": "invalid_request", "message": "brief (string) is required." } }
```
Some errors add fields beside `message` (for example `credits_required` and
`credits_available` on `402 out_of_credits`, `profile_id` on a profile-creation refusal). Every response, success or error, carries an `X-Request-Id` header to quote at support. Invalid JSON in any request body is `400 invalid_json`. A path whose id segment is not a UUID
never reaches a handler: it is `404 not_found`. CORS: the preflight allows `GET`, `POST`, `DELETE` and `OPTIONS` with the `authorization`,
`content-type`, `accept` and `idempotency-key` headers, so every route can be called from a
browser page as well as from servers and tools. ## Rate limits
60 requests a minute per API key on every route (`429 rate_limited`). Some routes add an hourly
budget per account, stated on the operation (`x-rate-limit`): voice-match 200 an hour, profile
extraction 5 an hour, brand mimic 3 an hour, saved edits 200 an hour, invoice 30, portal link 20,
checkout link 10. Polling a job counts against the 60 a minute. ## Credits
Drafts, polish, humanize, page rewrites and brand mimic cost credits from the same pool the app
uses; everything else is free (`x-credits` on each operation). A draft, polish or humanize is
priced by length: up to 5,000 words 1 credit, up to 10,000 words 2, up to 15,000 words 3,
charged per produced variant **after** it is delivered, so a failed call costs nothing. A page
rewrite is 1 credit per 1,500 rewritable words (minimum 1). Brand mimic costs one brand-mimic
credit. A wallet short of the price answers `402 out_of_credits` (or `402 insufficient_credits`
on a page rewrite). Every route that calls a model can also answer `402 budget_exceeded` when the
account''s monthly AI-spend ceiling is reached. ## Long drafts and background jobs
A draft above 4,000 words, or a polish or humanize above 3,000 words, is written in the
background: the call answers `202 Accepted` with a `job` object and a `poll` path. Poll
`GET /v1/jobs/{id}` (or `GET /v1/generations/{id}` for a draft) every 10 to 30 seconds.'
termsOfService: https://scriptgrain.com/terms
contact:
name: ScriptGrain support
email: support@scriptgrain.com
url: https://scriptgrain.com/support
license:
name: ScriptGrain Terms of Service
url: https://scriptgrain.com/terms
servers:
- url: https://auth.scriptgrain.com/functions/v1/api-v1
description: Production. Every path below is appended to this base.
security:
- ApiKey: []
tags:
- name: Guest sessions
description: Keyless sessions for agents whose person has no account yet.
paths:
/v1/guest:
post:
operationId: createGuestSession
tags:
- Guest sessions
summary: Start a guest session (no key)
description: 'Starts an unclaimed guest session with no API key and returns an `sg_guest_` key. A guest can
build one voice profile and score text against it (see the Guest sessions overview). Give the
person `claim_url`: they keep the profile in a free account, or delete it, from that link.
Unclaimed sessions are archived after 7 days and can still be claimed or deleted. The body is
optional; an unreadable body or an unknown `source` falls back to `api`. Caps count a ledger of
session starts, so deleting or claiming a session does not give its allowance back. The client
network is taken from a signed forward by the MCP worker, else the request''s own IP (IPv6 counts
per /64); with no usable IP the call is refused (fail closed).'
security: []
x-credits: free
x-rate-limit: 3 guest sessions in any 24 hours per client network (`guest.per_ip_daily`); a global cap on session starts in any 24 hours (`guest.daily_extractions`, default 200); no per-key limit applies because no key is needed
x-plans: all plans (no account needed)
requestBody:
required: false
content:
application/json:
schema:
$ref: '#/components/schemas/GuestCreateRequest'
example:
source: mcp
responses:
'201':
description: The guest session was created.
headers:
X-Request-Id:
$ref: '#/components/headers/X-Request-Id'
content:
application/json:
schema:
$ref: '#/components/schemas/GuestSessionCreated'
example:
guest_token: sg_guest_3f2b9c1e6a4d4e8f9b1a2c3d4e5f6a7b8c9d0e1f2a3b4c5d
expires_at: '2026-11-02T12:00:00.000Z'
claim_url: https://scriptgrain.com/claim/Qm3x9Zk1vT0aB7nYc2LhR8uE5wDfJgPoXiNsAtVyHbM
limits:
profiles: 1
extractions: 1
generations: 0
next: 'POST /v1/profiles with Authorization: Bearer <guest_token> and 3 to 10 samples of the person''s own writing (at most 25,000 words in all).'
note: 'Give the person claim_url: it keeps the voice profile in a free account. Unclaimed sessions are archived after 7 days and can still be claimed or deleted from the same link.'
'429':
description: '`rate_limited`: this network already started the per-day maximum of guest sessions (3 by default; the message names the configured limit).'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: '`internal_error`: the session could not be created.'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'503':
description: '`guest_unavailable`: guest sessions are switched off (`guest.enabled`), the global daily cap is reached, or no client IP could be determined.'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
get:
operationId: getGuestSession
tags:
- Guest sessions
summary: Get the state of a guest session
description: 'Authenticated with the guest key (`Authorization: Bearer sg_guest_...`). Reports the session
state and carries `claim_url` and `expires_at`. It answers 200 for expired, archived and claimed
sessions too, so an agent can tell which. It still answers when guest sessions are switched off.
A key that matches no guest session gets `401 invalid_api_key`. The generic API-key `401` for a
revoked or unknown `sg_live_` key does not apply here, since this route is only reached with a
guest key.'
x-credits: free
x-rate-limit: No separate limit; the 60 requests a minute per key limit is not applied to this route
x-plans: all plans (no account needed)
x-guest-allowed: true
responses:
'200':
description: The session state.
headers:
X-Request-Id:
$ref: '#/components/headers/X-Request-Id'
content:
application/json:
schema:
$ref: '#/components/schemas/GuestSessionState'
example:
status: active
claimed: false
archived: false
limits:
profiles: 1
extractions: 1
generations: 0
claim_url: https://scriptgrain.com/claim/Qm3x9Zk1vT0aB7nYc2LhR8uE5wDfJgPoXiNsAtVyHbM
expires_at: '2026-11-02T12:00:00.000Z'
'401':
description: '`invalid_api_key`: the guest key matches no session.'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'500':
description: '`internal_error`: the guest session lookup failed.'
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
GuestLimits:
type: object
required:
- profiles
- extractions
- generations
properties:
profiles:
type: integer
const: 1
extractions:
type: integer
const: 1
generations:
type: integer
const: 0
Error:
type: object
description: 'The error envelope every failure returns. `error.code` is stable and listed in this
description''s error-code table; `error.message` is for people and may change. Some codes
add fields beside them (`credits_required`, `credits_available`, `profile_id`,
`generation_id`, `retry_after_seconds`). A guest key''s errors also carry `claim_url` and
`expires_at` at the top level.
'
required:
- error
properties:
error:
type: object
required:
- code
- message
properties:
code:
type: string
examples:
- invalid_request
- out_of_credits
- profile_not_found
message:
type: string
additionalProperties: true
additionalProperties: true
example:
error:
code: invalid_request
message: brief (string) is required.
GuestSessionState:
type: object
allOf:
- $ref: '#/components/schemas/GuestEnvelope'
required:
- status
- claimed
- archived
- limits
properties:
status:
type: string
enum:
- active
- expired
- archived
- claimed
description: Claimed wins over archived, archived over expired. An active session whose key row is revoked or missing reports `expired`.
claimed:
type: boolean
archived:
type: boolean
limits:
$ref: '#/components/schemas/GuestLimits'
claim_url:
type: string
format: uri
expires_at:
type: string
format: date-time
GuestEnvelope:
type: object
description: 'The two extra top-level fields a guest key adds to every response on the guest routes, success or
error. Merged into the normal body: an error reads `{ "error": {...}, "claim_url": ..., "expires_at": ... }`.
'
required:
- claim_url
- expires_at
properties:
claim_url:
type: string
format: uri
description: Where the person claims or deletes the session.
expires_at:
type: string
format: date-time
additionalProperties: true
GuestCreateRequest:
type: object
properties:
source:
type: string
enum:
- api
- mcp
- cli
default: api
description: Where the session was started from. Any other value is ignored and recorded as `api`.
GuestSessionCreated:
type: object
required:
- guest_token
- expires_at
- claim_url
- limits
- next
- note
properties:
guest_token:
type: string
description: 'The `sg_guest_` key, shown once. Send it as `Authorization: Bearer sg_guest_...`.'
expires_at:
type: string
format: date-time
description: Seven days after creation.
claim_url:
type: string
format: uri
description: Where the person keeps the profile in a free account or deletes it.
limits:
$ref: '#/components/schemas/GuestLimits'
next:
type: string
description: A hint for the agent's next call.
note:
type: string
description: A reminder to hand claim_url to the person.
headers:
X-Request-Id:
description: A 16-character hex id for this request. Quote it when contacting support.
schema:
type: string
pattern: ^[0-9a-f]{16}$
example: 8c99d4ada706a856
securitySchemes:
ApiKey:
type: http
scheme: bearer
bearerFormat: sg_live_<secret> or sg_guest_<token>
description: 'An API key minted in the app (Settings, then API), sent as `Authorization: Bearer sg_live_…`.
The secret is shown once; the server stores a SHA-256 hash. A guest token from
`POST /v1/guest` (`sg_guest_…`) is sent the same way and may call only the routes marked
`x-guest-allowed`.
'
externalDocs:
description: Human-readable API documentation
url: https://scriptgrain.com/docs/api.md