> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testorim.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create (or re-use) a project

> Creates a project for the key's organization.

**This endpoint is idempotent-by-URL, and the status code tells you
which happened.** The base URL is normalised
(`https://` added when the scheme is missing, trailing slash on the
path removed) and then matched against existing non-archived
projects in the org:

* no match → the project is inserted and the response is
  **`201`** with `created: true`;
* match → the existing project's `lastUsedAt` is bumped and the
  response is **`200`** with `created: false`.

The normalised URL is checked by the SSRF guard before anything is
persisted, so a private or internal host is refused with `400` and
never stored.

When `name` is omitted it is derived from the hostname with a leading
`www.` stripped.




## OpenAPI

````yaml /api-reference/openapi.yaml post /api/projects
openapi: 3.1.0
info:
  title: Testorim API
  version: 1.0.0
  summary: AI browser QA. Trigger and inspect test runs from CI or your terminal.
  description: >
    Testorim runs plain-English browser QA tests in a real Playwright browser.

    This document describes the **API-key-authenticated subset** of the HTTP

    API, meaning the endpoints a CI pipeline, a terminal, or a third-party

    integration is expected to call.


    ## Scope and honesty notes


    * **This is not a frozen contract.** `1.0.0` is a documentation version,
      not a server version. The API is **unversioned in the URL**. There is
      no `/v1` prefix; every router mounts flat under `/api`.
    * **This is a subset.** The app's own SPA calls many more endpoints
      (billing, Polar/Clerk/GitHub webhooks, Slack and GitHub OAuth
      callbacks, fixtures, environments, schedules, alerts, visual
      baselines, run sharing, flakiness, test-data variables, perf budgets,
      role probes, bug reports, org/invite management). Those are
      deliberately **not** documented here: they are either session-oriented,
      provider-signed, or not stable enough to hand to an integrator.
      `PATCH`/`DELETE` on projects and procedures also exist in the code but
      are out of scope for this reference.

    ## Authentication


    Send the API key as an **HTTP Bearer token**:


    ```

    Authorization: Bearer tst_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    ```


    Testorim reads exactly one header, `Authorization`, and accepts either

    credential on it:


    1. a value matching `tst_live_…` (prefix + at least 16 more chars) is
       verified as an API key by SHA-256 hash lookup, or
    2. anything else is verified as a Clerk session JWT (the browser path).


    An API key is bound to **one user and one organization**. On every

    request the middleware pins `currentOrg` to the key's org, so a key

    issued for org A can never read or write org B, even when the owning

    user belongs to both. If the user has since been removed from that org,

    the key stops working (`401`).


    Every list and lookup is org-scoped. A resource belonging to another

    organization returns `404`, never `403`, so the API does not leak the

    existence of rows you cannot see.


    ## Role restrictions


    Members of an org with role `viewer` are read-only: any

    non-`GET`/`HEAD`/`OPTIONS` request is rejected with `403` and

    `code: "read_only_role"`. This applies to API-key callers too, because

    the key inherits the user's role in the bound org.


    ## Rate limiting


    Limits are enforced as a sliding window:


    | Limiter | Policy | Keyed by | Applied to |

    | --- | --- | --- | --- |

    | `api:global` | 600 / minute | client IP | every `/api/*` request |

    | `procedure:minute` | 30 / minute | authenticated user id | `POST
    /api/runs/trigger` |

    | `api:read` | 120 / minute | authenticated user id | `GET /api/runs/active`
    |

    | `auth:strict` | 5 / 15 minutes | client IP | **failed** credential checks
    |


    A throttled request returns `429`, a JSON body of

    `{ "error": …, "retryAfter": <seconds> }`, and a `Retry-After` response

    header. **There are no `X-RateLimit-*` headers**. The middleware sets

    only `Retry-After`, so do not write a client that depends on quota

    headers.


    Rate limits are separate from **plan quotas**. Exhausting the

    organization's monthly run allowance also returns `429`, but from

    `checkRunLimit` rather than the limiter, and with no `Retry-After`.


    ## Request body rules


    * JSON bodies are capped at **1 MB**.

    * Any string anywhere in the body containing a NUL byte (`U+0000`)
      rejects the whole request with `400` before it reaches a handler.
    * Bodies are validated with Zod. A schema failure returns `400` with
      `{ "error": "Invalid request body", "issues": [...] }`, where `issues`
      is the raw `ZodError.issues` array.
  contact:
    name: Testorim support
    email: info@fulgic.com
    url: https://testorim.com
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://app.testorim.com
    description: >-
      Production. Single-origin deployment: Caddy on one GCP VM serves the SPA
      at `/` and reverse-proxies `/api/*` and `/ws` to the backend. This is also
      the default API base URL used by the Testorim CLI.
  - url: http://localhost:3001
    description: >-
      A locally running Testorim backend, for self-hosted or development use.
      The default port is 3001.
security:
  - ApiKeyAuth: []
tags:
  - name: Runs
    description: >-
      Trigger a test run and read its result. `POST /api/runs/trigger` is the
      endpoint CI actually uses.
  - name: Procedures
    description: Saved, replayable test sequences belonging to a project.
  - name: Projects
    description: A website-under-test, scoped to an organization.
  - name: API keys
    description: >-
      Mint, list and revoke API keys. Creating a key requires a browser session.
      See the operation notes.
  - name: Identity
    description: Who the presented credential belongs to.
paths:
  /api/projects:
    post:
      tags:
        - Projects
      summary: Create (or re-use) a project
      description: |
        Creates a project for the key's organization.

        **This endpoint is idempotent-by-URL, and the status code tells you
        which happened.** The base URL is normalised
        (`https://` added when the scheme is missing, trailing slash on the
        path removed) and then matched against existing non-archived
        projects in the org:

        * no match → the project is inserted and the response is
          **`201`** with `created: true`;
        * match → the existing project's `lastUsedAt` is bumped and the
          response is **`200`** with `created: false`.

        The normalised URL is checked by the SSRF guard before anything is
        persisted, so a private or internal host is refused with `400` and
        never stored.

        When `name` is omitted it is derived from the hostname with a leading
        `www.` stripped.
      operationId: createProject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateProjectRequest'
            examples:
              minimal:
                summary: URL only, name derived from the hostname
                value:
                  baseUrl: https://example.com
              named:
                summary: Explicit name
                value:
                  baseUrl: https://staging.example.com/app
                  name: Example staging
      responses:
        '200':
          description: >-
            A project with this normalised base URL already existed in the
            organization; it was returned with `lastUsedAt` refreshed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProjectEnvelopeExisting'
        '201':
          description: A new project was created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ProjectEnvelopeCreated'
        '400':
          description: >-
            Body failed validation (`baseUrl` must be 3..500 chars and parse as
            a URL once a scheme is added), or the URL was refused by the SSRF
            guard.
          content:
            application/json:
              schema:
                anyOf:
                  - $ref: '#/components/schemas/ValidationError'
                  - $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/ReadOnlyRole'
        '429':
          $ref: '#/components/responses/RateLimited'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    CreateProjectRequest:
      type: object
      title: CreateProjectRequest
      required:
        - baseUrl
      properties:
        baseUrl:
          type: string
          minLength: 3
          maxLength: 500
          description: >-
            The site under test. The scheme may be omitted, in which case
            `https://` is prepended, and a trailing slash on the path is removed
            before storage and before the duplicate check. Private, loopback,
            link-local and cloud-metadata hosts are rejected.
        name:
          type: string
          minLength: 1
          maxLength: 100
          description: >-
            Display name. Defaults to the hostname with a leading `www.`
            stripped.
      additionalProperties: false
    ProjectEnvelopeExisting:
      type: object
      title: ProjectEnvelopeExisting
      required:
        - project
        - created
      properties:
        project:
          $ref: '#/components/schemas/Project'
        created:
          type: boolean
          const: false
    ProjectEnvelopeCreated:
      type: object
      title: ProjectEnvelopeCreated
      required:
        - project
        - created
      properties:
        project:
          $ref: '#/components/schemas/Project'
        created:
          type: boolean
          const: true
    ValidationError:
      type: object
      title: ValidationError
      description: >-
        Emitted by `parseBody` / `parseQuery` when a Zod schema rejects the
        input. `issues` is the raw `ZodError.issues` array, passed through
        verbatim.
      required:
        - error
        - issues
      properties:
        error:
          type: string
          enum:
            - Invalid request body
            - Invalid query parameters
        issues:
          type: array
          description: Raw Zod issues.
          items:
            type: object
            properties:
              code:
                type: string
              path:
                type: array
                items:
                  type:
                    - string
                    - integer
              message:
                type: string
            additionalProperties: true
    Error:
      type: object
      title: Error
      description: >-
        The universal error envelope. Every failing handler in this surface
        responds with a JSON object carrying a human-readable `error` string;
        some add extra fields (see the other error schemas).
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable message. Not a stable machine-readable code.
      additionalProperties: true
    Project:
      type: object
      title: Project
      description: >-
        A website-under-test. Handlers return the whole DB row, so several
        internal columns are visible.
      required:
        - id
        - orgId
        - name
        - baseUrl
        - createdAt
        - lastUsedAt
      properties:
        id:
          type: string
          format: uuid
        orgId:
          type: string
          format: uuid
          description: The owning organization. Always the key's bound org.
        name:
          type: string
        baseUrl:
          type: string
          description: >-
            Normalised so the scheme is present and the path has no trailing
            slash.
        createdAt:
          type: string
          format: date-time
        lastUsedAt:
          type: string
          format: date-time
          description: >-
            Bumped on project update and on a duplicate create. Drives the
            ordering of `GET /api/projects`.
        archivedAt:
          type:
            - string
            - 'null'
          format: date-time
          description: >-
            Soft-delete marker. Always null in responses, because archived
            projects are filtered out of every read path.
        storageStateJson:
          type:
            - 'null'
            - object
            - string
          description: >-
            Captured Playwright `storageState` for login reuse, encrypted at
            rest with AES-256-GCM (`v1:` scheme). Present in the response
            because the handler selects the whole row. Treat it as an opaque
            ciphertext blob. It is not a usable session and has no documented
            plaintext shape.
          additionalProperties: true
        storageStateCapturedAt:
          type:
            - string
            - 'null'
          format: date-time
        timezone:
          type:
            - string
            - 'null'
          description: >-
            IANA timezone applied to every browser context. Null = browser
            default.
        locale:
          type:
            - string
            - 'null'
        geolocationJson:
          type:
            - object
            - 'null'
          description: Geolocation override applied to every browser context.
          properties:
            latitude:
              type: number
              minimum: -90
              maximum: 90
            longitude:
              type: number
              minimum: -180
              maximum: 180
            accuracy:
              type: number
              minimum: 0
              maximum: 10000
          additionalProperties: false
        appContextJson:
          type:
            - object
            - 'null'
          description: >-
            User-provided, non-secret app profile used as planner context.
            Written by `PATCH /api/projects/{id}` (out of scope here) against a
            strict schema.
          properties:
            appType:
              type: string
              maxLength: 80
            summary:
              type: string
              maxLength: 1200
            authModel:
              type: string
              maxLength: 800
            keyFlows:
              type: array
              maxItems: 12
              items:
                type: string
                maxLength: 160
            domainTerms:
              type: array
              maxItems: 30
              items:
                type: string
                maxLength: 80
            testNotes:
              type: string
              maxLength: 1200
          additionalProperties: false
        appMapJson:
          type:
            - 'null'
            - object
            - array
          description: >-
            Machine-collected map of routes, titles and visible labels observed
            during successful runs, used to ground the planner. Server-written
            only; no stable public shape.
          additionalProperties: true
    ReadOnlyRoleError:
      type: object
      title: ReadOnlyRoleError
      description: The one error in this surface with a stable machine-readable code.
      required:
        - error
        - code
      properties:
        error:
          type: string
          const: Viewers have read-only access to this workspace
        code:
          type: string
          const: read_only_role
    RateLimitError:
      type: object
      title: RateLimitError
      description: Emitted by the rate-limit middleware alongside a `Retry-After` header.
      required:
        - error
      properties:
        error:
          type: string
          description: The limiter's reason, e.g. `Rate limit exceeded. Try again in 42s.`
        retryAfter:
          type:
            - integer
            - 'null'
          description: >-
            Seconds until the window frees. Mirrors `Retry-After`. May be
            absent/null when the limiter did not report a reset time, in which
            case the header defaults to 60.
      additionalProperties: true
  responses:
    Unauthorized:
      description: |
        No `Authorization: Bearer …` header, or the credential did not
        verify. Distinct messages the code can return:

        * `Missing or invalid Authorization header`
        * `Invalid or revoked API key`
        * `API key owner not found`
        * `API key's organization is no longer accessible`. The key's user
          has been removed from the org it is bound to
        * `Invalid token` / `Token missing sub claim`. Clerk JWT path

        Repeated failures burn the `auth:strict` bucket (5 per 15 minutes
        per IP) and then return `429` instead.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Invalid or revoked API key
    ReadOnlyRole:
      description: >-
        The credential's user has the `viewer` role in the bound organization,
        and viewers may not make mutating requests.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ReadOnlyRoleError'
    RateLimited:
      description: >-
        Throttled. Every `/api/*` route sits behind `api:global` (600 / minute
        per IP); some routes add a tighter per-user limiter.
      headers:
        Retry-After:
          description: Seconds until the window frees up.
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: tst_live_<32 url-safe base64 chars>
      description: |
        Send `Authorization: Bearer tst_live_…`.

        Format (`services/api-keys.ts`): the literal prefix `tst_live_`
        followed by 24 random bytes rendered as 32 base64url characters.
        Only the SHA-256 hash is stored server-side. The shape check that
        routes a token down the API-key path rather than the Clerk JWT path
        requires the `tst_live_` prefix and a total length of at least 25
        characters.

        Keys are minted in the dashboard at `/settings/team`. The same header
        also accepts a Clerk session JWT, which is how the web app
        authenticates, but the JWT path is out of scope for this document.

````

## Related topics

- [Create a project](/getting-started/create-a-project.md)
- [Projects](/projects/projects.md)
- [Reliability](/troubleshooting/reliability.md)
- [Debugging a failed run](/test-execution/debugging.md)
- [Create your first test](/getting-started/first-test.md)
