ScriptGrain Jobs API

Background jobs for long drafts, polish and humanize.

GitHub OpenAPI

Operations 2

GET /v1/jobs/{id} Get a background job #
POST /v1/jobs/{id}/cancel Cancel a background job #

Specifications

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • 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.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/scriptgrain-com:scriptgrain-com-jobs-api"
All apis
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.

Get an API 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 Specification

scriptgrain-com-jobs-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: ScriptGrain Jobs 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: Jobs
  description: Background jobs for long drafts, polish and humanize.
paths:
  /v1/jobs/{id}:
    get:
      operationId: getJob
      tags:
      - Jobs
      summary: Get a background job
      description: 'A background job (a long draft, polish or humanise): the job object plus `result` once there is

        one. Readable by the account that started it and by any key of the job''s organisation. A draft

        gets `result` when it has succeeded; a polish or humanise gets it once it has finished, and a

        run that stopped part way (cancelled, out of credits, failed) returns the text it revised

        with `partial: true`.'
      x-credits: free
      x-rate-limit: 60 requests a minute per key (global)
      x-plans: all plans
      parameters:
      - name: id
        in: path
        required: true
        description: Job id.
        schema:
          $ref: '#/components/schemas/Uuid'
      responses:
        '200':
          description: The job.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobWithResult'
              example:
                id: 5d8e2f1a-7b3c-4a9d-8e6f-0a1b2c3d4e5f
                kind: draft
                status: succeeded
                cancel_requested: false
                generation_id: 9a1c4e7b-2d3f-4b6a-8c5d-1e2f3a4b5c6d
                target_words: 9000
                units_done: 6
                units_total: 6
                words_done: 9120
                credits_cap: 2
                credits_charged: 2
                error: null
                created_at: '2026-10-20T08:41:17.000Z'
                finished_at: '2026-10-20T08:47:02.000Z'
                result:
                  generation_id: 9a1c4e7b-2d3f-4b6a-8c5d-1e2f3a4b5c6d
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: '`job_not_accessible`: the job is in neither the key''s organisation nor the key owner''s workspace.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '`job_not_found`: no job with that id.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          description: '`internal_error`: the job lookup failed.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /v1/jobs/{id}/cancel:
    post:
      operationId: cancelJob
      tags:
      - Jobs
      summary: Cancel a background job
      description: 'Asks the worker to stop before its next section; the response is the job with

        `cancel_requested: true`, and `status` becomes `cancelled` once the worker stops. What was

        delivered stays delivered and is charged by its tier. Only the account that started the job

        may cancel it. Cancelling a job that has already finished changes nothing and returns its

        final state. There is no request body.'
      x-credits: free (the job is charged for what it delivered, by its own tier rule)
      x-rate-limit: 60 requests a minute per key (global)
      x-plans: all plans
      parameters:
      - name: id
        in: path
        required: true
        description: Job id.
        schema:
          $ref: '#/components/schemas/Uuid'
      responses:
        '200':
          description: The job after the cancel request (or in its final state if already finished).
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobWithResult'
              example:
                id: 5d8e2f1a-7b3c-4a9d-8e6f-0a1b2c3d4e5f
                kind: draft
                status: running
                cancel_requested: true
                generation_id: 9a1c4e7b-2d3f-4b6a-8c5d-1e2f3a4b5c6d
                target_words: 9000
                units_done: 3
                units_total: 6
                words_done: 4510
                credits_cap: 2
                credits_charged: 0
                error: null
                created_at: '2026-10-20T08:41:17.000Z'
                finished_at: null
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: '`job_not_accessible`: the job is not in the key''s organisation or workspace. `job_not_cancellable`: a teammate started it; only that account can cancel.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '`job_not_found`: no job with that id.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          description: '`internal_error`: the job lookup or the cancel update failed.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  responses:
    RateLimited:
      description: '`rate_limited`: more than 60 requests in a minute on this key, or a route''s hourly budget is used.'
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: rate_limited
              message: Rate limit exceeded (60 req/min per API key). Try again shortly.
    Unauthorized:
      description: '`unauthorized`: the `Authorization` header is missing or malformed. `invalid_api_key`: the key

        is not recognised or was revoked. For a guest key also `guest_expired` and `guest_claimed`.

        '
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: invalid_api_key
              message: API key not recognised.
  schemas:
    Job:
      type: object
      description: 'A background job: a long draft (`kind: draft`), or a long polish or humanize. `status`:

        `queued` (waiting), `running` (writing), `succeeded`, `cancelled` (stopped at your request;

        delivered text kept and charged), `stopped_no_credits` (a tier charge failed; delivered

        text kept, the rest not written), `failed` (retries exhausted; delivered text kept and

        charged; `error` says why). `units_done` of `units_total` sections are written, `words_done`

        words so far; `credits_cap` is the tier asked for and `credits_charged` rises as tiers are

        crossed. The job''s `result` (on `GET /v1/jobs/{id}`) is described there.

        '
      required:
      - id
      - kind
      - status
      - cancel_requested
      - generation_id
      - target_words
      - units_done
      - units_total
      - words_done
      - credits_cap
      - credits_charged
      - error
      - created_at
      - finished_at
      properties:
        id:
          $ref: '#/components/schemas/Uuid'
        kind:
          type: string
          enum:
          - draft
          - polish
          - humanize
        status:
          type: string
          enum:
          - queued
          - running
          - succeeded
          - failed
          - cancelled
          - stopped_no_credits
        cancel_requested:
          type: boolean
        generation_id:
          type:
          - string
          - 'null'
          format: uuid
          description: The generation a draft job writes, or the one a polish/humanize was filed against; null when none.
        target_words:
          type: integer
        units_done:
          type: integer
        units_total:
          type: integer
        words_done:
          type: integer
        credits_cap:
          type: integer
        credits_charged:
          type: integer
        error:
          type:
          - object
          - 'null'
          required:
          - code
          - message
          properties:
            code:
              type: string
            message:
              type:
              - string
              - 'null'
        created_at:
          type: string
          format: date-time
        finished_at:
          type:
          - string
          - 'null'
          format: date-time
      example:
        id: 7a1c2d3e-4f50-4a6b-8c7d-9e0f1a2b3c4d
        kind: draft
        status: running
        cancel_requested: false
        generation_id: 3f2b9c1e-6a4d-4e8f-9b1a-2c3d4e5f6a7b
        target_words: 12000
        units_done: 3
        units_total: 7
        words_done: 5140
        credits_cap: 3
        credits_charged: 2
        error: null
        created_at: '2026-10-26T10:00:00.000Z'
        finished_at: null
    Uuid:
      type: string
      format: uuid
      description: A UUID. Path ids that are not UUID-shaped never match a route (404 `not_found`).
      example: 3f2b9c1e-6a4d-4e8f-9b1a-2c3d4e5f6a7b
    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.
    JobWithResult:
      description: The job object plus `result` when there is one.
      allOf:
      - $ref: '#/components/schemas/Job'
      - type: object
        properties:
          result:
            description: 'Present for a draft once `succeeded` (`generation_id` only), and for a polish or humanise

              once it has finished with text (`content`, `word_count`, `voice_match_score`; `partial`

              only when it did not succeed).

              '
            oneOf:
            - type: object
              required:
              - generation_id
              properties:
                generation_id:
                  $ref: '#/components/schemas/Uuid'
            - type: object
              required:
              - content
              - word_count
              - voice_match_score
              properties:
                content:
                  type: string
                word_count:
                  type: integer
                voice_match_score:
                  type:
                  - number
                  - 'null'
                  description: Null for humanise.
                partial:
                  type: boolean
                  const: true
                  description: Present and true when the job stopped before finishing (cancelled, out of credits or failed); content is the revised sections only.
  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