ScriptGrain Billing API

Subscription state and Stripe-hosted links. Never plan-gated; nothing here moves money through the API.

GitHub OpenAPI

Operations 4

GET /v1/billing Get the subscription and credit summary #
GET /v1/billing/invoice Get the latest invoice #

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-billing-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-billing-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: ScriptGrain Billing 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: Billing
  description: Subscription state and Stripe-hosted links. Never plan-gated; nothing here moves money through the API.
paths:
  /v1/billing:
    get:
      operationId: getBilling
      tags:
      - Billing
      summary: Get the subscription and credit summary
      description: 'Plan, billing cycle, status, remaining credits and renewal date for the billing entity the key

        bills (the team organisation, or the key owner''s personal subscription). Billing routes skip the

        plan gate, so this works on every plan. The renewal date costs one Stripe lookup; if the account

        has no live subscription, or the lookup fails, the call still succeeds with `current_period_end`

        null and `cancel_at_period_end` false.'
      x-credits: free
      x-rate-limit: 60 requests a minute per key (global)
      x-plans: all plans (billing routes skip the plan gate)
      responses:
        '200':
          description: The billing summary.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BillingSummary'
              example:
                plan: operator
                billing_cycle: monthly
                status: active
                source: personal
                credits:
                  generation: 42
                  topup: 7
                  brand_mimic: 2
                extractions_this_month: 1
                current_period_end: '2026-11-01T00:00:00.000Z'
                cancel_at_period_end: false
                has_billing_account: true
                upgrade_url: https://scriptgrain.com/settings#plans
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: '`no_subscription`: no billing context could be resolved for this key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
  /v1/billing/invoice:
    get:
      operationId: getLatestInvoice
      tags:
      - Billing
      summary: Get the latest invoice
      description: 'The most recent Stripe invoice for the billing entity, with a hosted web link and a direct PDF

        link. Billing routes skip the plan gate. Shares an hourly pool of 30 requests per account with the

        in-app latest-invoice function. A Stripe error other than a missing key is not caught by the

        handler and surfaces as `500 internal_error`.'
      x-credits: free
      x-rate-limit: 60 requests a minute per key (global); plus 30 requests an hour per account, shared with the in-app latest-invoice function
      x-plans: all plans (billing routes skip the plan gate)
      responses:
        '200':
          description: The latest invoice.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvoiceSummary'
              example:
                id: in_1SabcDEF2gHiJkLm
                number: SG-0042
                status: paid
                amount_paid: 4900
                amount_due: 0
                currency: gbp
                created: '2026-10-01T09:00:12.000Z'
                period_end: '2026-10-01T09:00:12.000Z'
                hosted_invoice_url: https://invoice.stripe.com/i/acct_1/live_abc
                invoice_pdf: https://pay.stripe.com/invoice/acct_1/live_abc/pdf
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: '`no_subscription`: no billing context could be resolved for this key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: '`no_billing_account`: the account has never had a paid subscription (no Stripe customer). `no_invoices`: the customer exists but has no invoices yet.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '`rate_limited`: the hourly pool of 30 invoice requests per account is used up, or the global 60 requests a minute per key limit was hit.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: '`misconfigured`: Stripe is not configured on the server. `internal_error`: an unexpected error, including a failed Stripe call.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /v1/billing/portal-link:
    post:
      operationId: createPortalLink
      tags:
      - Billing
      summary: Create a Stripe customer-portal link
      description: 'Mints a short-lived Stripe customer-portal session. Plan changes, cancellations and payment-method

        updates complete in the browser on Stripe''s pages; nothing in the API changes the subscription.

        An account with no Stripe customer has no portal, so the call answers 200 with `portal_url` null

        and an `upgrade_url`. Takes no request body. Billing routes skip the plan gate. Shares an hourly

        pool of 20 requests per account with the in-app customer-portal function. A Stripe error other

        than a missing key surfaces as `500 internal_error`.'
      x-credits: free
      x-rate-limit: 60 requests a minute per key (global); plus 20 requests an hour per account, shared with the in-app customer-portal function
      x-plans: all plans (billing routes skip the plan gate)
      responses:
        '200':
          description: A portal link, or the upgrade fallback when the account has never subscribed.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PortalLink'
              examples:
                portal:
                  summary: Account with a Stripe customer
                  value:
                    portal_url: https://billing.stripe.com/p/session/live_abc
                    upgrade_url: https://scriptgrain.com/settings#plans
                    message: Open portal_url in a browser to change plan, view invoices or update payment details. Portal links expire after a few minutes — mint a fresh one when needed.
                fallback:
                  summary: Never-subscribed account
                  value:
                    portal_url: null
                    upgrade_url: https://scriptgrain.com/settings#plans
                    message: No billing account yet — this account has never had a paid subscription. Pick a plan at the upgrade_url; the billing portal becomes available after the first subscription.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: '`no_subscription`: no billing context could be resolved for this key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '`rate_limited`: the hourly pool of 20 portal requests per account is used up, or the global 60 requests a minute per key limit was hit.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: '`misconfigured`: Stripe is not configured on the server. `internal_error`: an unexpected error, including a failed Stripe call.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /v1/billing/checkout-link:
    post:
      operationId: createCheckoutLink
      tags:
      - Billing
      summary: Create a Stripe Checkout link for a new subscription
      description: 'Mints a Stripe Checkout session to start a new personal subscription (the never-subscribed upsell

        path). Payment completes in the browser on Stripe''s hosted page and the plan activates after

        payment. Success and cancel redirect URLs are fixed server-side. Team subscriptions (seat

        quantities) are not exposed here; a key that bills a team organisation, or an account whose

        Stripe subscription is `active` or `trialing`, gets `409 already_subscribed` and should use the

        portal link. Currency is the requested one, else the owner''s sign-up market (`us` gives usd, else

        gbp); an existing Stripe customer''s own currency overrides both. The hourly pool of 10 requests per

        account is charged before the body is validated. Billing routes skip the plan gate.'
      x-credits: free
      x-rate-limit: 60 requests a minute per key (global); plus 10 requests an hour per account, shared with the in-app create-checkout function
      x-plans: all plans (billing routes skip the plan gate)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckoutLinkRequest'
            example:
              plan: writer
              billing_cycle: annual
              currency: gbp
      responses:
        '200':
          description: The Checkout link.
          headers:
            X-Request-Id:
              $ref: '#/components/headers/X-Request-Id'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutLink'
              example:
                checkout_url: https://checkout.stripe.com/c/pay/cs_live_abc
                plan: writer
                billing_cycle: annual
                currency: gbp
                message: Open checkout_url in a browser to complete the subscription on Stripe's hosted page. The plan activates automatically after payment; credits appear within a minute.
        '400':
          description: '`invalid_request`: `plan` is missing or not one of writer, operator, studio, agency; `billing_cycle` is present and not `monthly` or `annual`; or `currency` is present and not `gbp` or `usd`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          description: '`no_subscription`: no billing context could be resolved for this key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '`already_subscribed`: the key bills a team organisation, or the account''s Stripe subscription is active or trialing. Use the portal link.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '`rate_limited`: the hourly pool of 10 checkout requests per account is used up, or the global 60 requests a minute per key limit was hit.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: '`misconfigured`: Stripe is not configured, or no Stripe price is set for that plan and cycle. `internal_error`: an unexpected error, including a failed Stripe call.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: '`upstream_error`: Stripe created the session but returned no checkout URL.'
          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.
    InternalError:
      description: '`internal_error`: a server-side failure. Quote `X-Request-Id` to support.'
      headers:
        X-Request-Id:
          $ref: '#/components/headers/X-Request-Id'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: internal_error
              message: Unexpected server error. Quote your X-Request-Id to support.
    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:
    InvoiceSummary:
      type: object
      required:
      - id
      - number
      - status
      - amount_paid
      - amount_due
      - currency
      - created
      - period_end
      - hosted_invoice_url
      - invoice_pdf
      properties:
        id:
          type: string
          description: Stripe invoice id.
        number:
          type:
          - string
          - 'null'
        status:
          type:
          - string
          - 'null'
          description: Stripe invoice status (for example draft, open, paid, void, uncollectible).
        amount_paid:
          type: integer
          description: Minor units.
        amount_due:
          type: integer
          description: Minor units.
        currency:
          type: string
          description: Lower-case ISO currency code from Stripe.
        created:
          type:
          - string
          - 'null'
          format: date-time
        period_end:
          type:
          - string
          - 'null'
          format: date-time
        hosted_invoice_url:
          type:
          - string
          - 'null'
          format: uri
          description: Stripe-hosted web view.
        invoice_pdf:
          type:
          - string
          - 'null'
          format: uri
          description: Stripe-hosted PDF; downloads without auth.
    BillingSummary:
      type: object
      required:
      - plan
      - billing_cycle
      - status
      - source
      - credits
      - extractions_this_month
      - current_period_end
      - cancel_at_period_end
      - has_billing_account
      - upgrade_url
      properties:
        plan:
          type: string
          description: Current plan.
          enum:
          - reader
          - writer
          - operator
          - studio
          - agency
        billing_cycle:
          type: string
          description: Billing cycle as stored on the account. The code does not constrain the value beyond the two cycles below.
          enum:
          - monthly
          - annual
        status:
          type: string
          description: Subscription status as stored on the account (not fixed in code to a closed list).
        source:
          type: string
          description: Whether the key bills the owner's personal subscription or a team organisation.
          enum:
          - personal
          - team
        credits:
          type: object
          required:
          - generation
          - topup
          - brand_mimic
          properties:
            generation:
              type: integer
            topup:
              type: integer
            brand_mimic:
              type: integer
        extractions_this_month:
          type: integer
        extractions_lifetime_used:
          type: integer
          description: Lifetime extractions used. Present only when `plan` is `reader`, where the lifetime taster cap applies.
        current_period_end:
          type:
          - string
          - 'null'
          format: date-time
          description: Renewal date. Null without a live Stripe subscription, or when the Stripe lookup failed.
        cancel_at_period_end:
          type: boolean
        has_billing_account:
          type: boolean
          description: True when the account has a Stripe customer.
        upgrade_url:
          type: string
          format: uri
    CheckoutLink:
      type: object
      required:
      - checkout_url
      - plan
      - billing_cycle
      - currency
      - message
      properties:
        checkout_url:
          type: string
          format: uri
        plan:
          type: string
          enum:
          - writer
          - operator
          - studio
          - agency
        billing_cycle:
          type: string
          description: Defaults to `monthly` when omitted; any other value is `400 invalid_request`.
          enum:
          - monthly
          - annual
        currency:
          type: string
          enum:
          - gbp
          - usd
          description: The currency Checkout was created in, after the existing-customer override.
        message:
          type: string
    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.
    CheckoutLinkRequest:
      type: object
      required:
      - plan
      properties:
        plan:
          type: string
          enum:
          - writer
          - operator
          - studio
          - agency
        billing_cycle:
          type: string
          enum:
          - monthly
          - annual
          default: monthly
          description: Any value other than `annual` (including a missing or invalid one) is treated as `monthly`.
        currency:
          type:
          - string
          - 'null'
          enum:
          - gbp
          - usd
          - null
          description: Optional. Null or absent falls back to the owner's sign-up market, then gbp. An existing Stripe customer's currency overrides it.
    PortalLink:
      type: object
      required:
      - portal_url
      - upgrade_url
      - message
      properties:
        portal_url:
          type:
          - string
          - 'null'
          format: uri
          description: Stripe portal session URL. Null when the account has never had a Stripe customer.
        upgrade_url:
          type: string
          format: uri
        message:
          type: string
  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