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

# Create session

> Create a new session. See [Sessions](https://docs.galtea.ai/concepts/product/version/session).

> [!WARNING]
>
> You are reading the docs of Galtea 5.22. [Read this page in the latest version](https://docs.galtea.ai/api-reference/sessions/create-session.md).


## OpenAPI

````yaml /v5.22/openapi.json post /sessions
openapi: 3.0.0
info:
  version: 1.0.0
  title: Product Management Service API
  description: API documentation for Product Management Service
  contact:
    name: Galtea AI
servers:
  - url: https://api.galtea.ai
security:
  - bearerAuth: []
tags: []
externalDocs:
  description: Galtea Platform Documentation
  url: https://docs.galtea.ai
paths:
  /sessions:
    post:
      tags:
        - sessions
      summary: Create session
      description: >-
        Create a new session. See
        [Sessions](https://docs.galtea.ai/concepts/product/version/session).
      operationId: createSession
      parameters:
        - $ref: '#/components/parameters/Prefer'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/SessionCreate'
                - description: >-
                    Session creation input. `versionId` is optional: when
                    omitted, provide `productId` and the API reuses the
                    product's latest version (creating a default first version
                    if the product has none). One of `versionId` or `productId`
                    is required. `testCaseId` and `isProduction` are
                    independent: a session can be production (no testCaseId),
                    test-driven non-production (testCaseId set, isProduction
                    defaults to false), or externally-ingested non-production
                    (no testCaseId, isProduction explicitly false, typical for
                    imported traces). The only forbidden combination is
                    `testCaseId` set together with `isProduction=true`. When
                    `testCaseId` is set, `context` is rejected because it would
                    be derived from the test case.
      responses:
        '201':
          description: >-
            Session created successfully. On `Prefer: return=minimal`, or when
            the read after the write fails, the answer has no body.
          headers:
            Location:
              schema:
                type: string
                description: The path of the new resource
              required: true
              description: The path of the new resource
            Content-Location:
              schema:
                type: string
                description: >-
                  The path of the resource in the body; absent when there is no
                  body
              required: false
              description: >-
                The path of the resource in the body; absent when there is no
                body
            Preference-Applied:
              schema:
                type: string
                enum:
                  - return=minimal
                description: 'Present when the API honored `Prefer: return=minimal`'
              required: false
              description: 'Present when the API honored `Prefer: return=minimal`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Session'
        '400':
          description: >-
            Invalid request: a malformed field, a status outside the session
            statuses, or an internal field ("id", "launchedRunId")
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Version, product, test case or run not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - bearerAuth: []
components:
  parameters:
    Prefer:
      schema:
        $ref: '#/components/schemas/Prefer'
      required: false
      description: >-
        Send `return=minimal` to get no body back from a write and skip reading
        the resource: a create answers `201` with only `Location`, and an update
        answers `204`.
      name: Prefer
      in: header
  schemas:
    SessionCreate:
      type: object
      properties:
        versionId:
          type: string
          nullable: true
          description: >-
            Version ID to create the session for. Optional when productId is
            provided; one of versionId or productId is required.
          example: ver_123
        productId:
          type: string
          nullable: true
          description: >-
            Product to anchor the session when versionId is omitted. The API
            reuses the product's latest version or creates a default one.
            Ignored when versionId is provided.
          example: prod_123
        customId:
          type: string
          nullable: true
          description: Optional caller-defined identifier for the session
          example: my-session-1
        testCaseId:
          type: string
          nullable: true
          description: >-
            Test case to link this session to. Forbidden when isProduction=true.
            Defaults to omitted, in which case isProduction defaults to true.
          example: tc_123
        isProduction:
          type: boolean
          nullable: true
          description: >-
            Whether the session represents real production traffic. Defaults to
            true when testCaseId is omitted and false when testCaseId is set.
            May be set explicitly to false without a testCaseId for
            externally-ingested sessions (e.g. trace imports).
        context:
          anyOf:
            - type: string
            - type: object
              additionalProperties:
                nullable: true
            - nullable: true
          description: >-
            Additional context for the session. Accepts a plain string or a
            structured JSON object. Forbidden when testCaseId is set (the
            context is derived from the test case).
        metadata:
          nullable: true
          description: Arbitrary metadata, stored as sent.
          example:
            key: value
        status:
          type: string
          nullable: true
          enum:
            - PENDING
            - COMPLETED
            - FAILED
            - null
          default: PENDING
          description: >-
            Initial session status. Defaults to PENDING (open, accepts new
            turns); the session closes on an explicit finish or the product
            auto-close sweep.
        runId:
          type: string
          nullable: true
          description: >-
            Run to attribute this session to, so several sessions a client
            creates are grouped together. It must name a run you opened with
            POST /runs: a run a platform launch opened settles with that launch
            and is rejected here, as is a deleted, finished, other-product or
            other-version run. Forbidden when isProduction is true.
          example: run_123
    Session:
      type: object
      properties:
        id:
          type: string
          example: session_123
        customId:
          type: string
          nullable: true
          example: custom_session_123
        versionId:
          type: string
          example: ver_123
        userId:
          type: string
          nullable: true
          example: user_123
        testCaseId:
          type: string
          nullable: true
          example: tc_123
        context:
          type: object
          nullable: true
          additionalProperties:
            nullable: true
          description: >-
            Structured context data. For plain text context, format is { value:
            "..." }
          example:
            value: Session context information
        stoppingReason:
          type: string
          nullable: true
          example: GOAL_ACHIEVED
        recordingUri:
          type: string
          nullable: true
          description: >-
            Storage URI of the full-call recording for a telephony-evaluation
            session, returned under `STORAGE_PUBLIC_BASE_URL` when the
            deployment configures one. Null for non-telephony sessions or before
            the recording is processed. Resolve to a playable URL via GET
            /storage?uri=.
          example: https://files.galtea.ai/audio/org_123/session_abc-recording.mp3
        error:
          type: string
          nullable: true
          example: >-
            External API responded with HTTP 422: Unprocessable Entity —
            {"detail":"model not found"}
        status:
          type: string
          enum:
            - PENDING
            - COMPLETED
            - FAILED
          example: PENDING
        isProduction:
          type: boolean
          description: >-
            True when the session represents real production traffic (no
            associated test case).
          example: false
        isSeed:
          type: boolean
          readOnly: true
          description: >-
            True when the session holds the predefined conversation of a test
            case and is never executed. Server-managed and read-only.
          example: false
        metadata:
          nullable: true
          description: >-
            Arbitrary metadata, returned as stored. Usually an object, but any
            JSON value is accepted.
          example:
            key: value
        runId:
          type: string
          nullable: true
          description: >-
            The run that created this session. Null for a session created
            outside a launch (production traffic, an imported trace). A session
            a run only scored names no run here; filter with `involvedInRunIds`
            to reach those too.
          example: run_123
        endUser:
          type: string
          nullable: true
          readOnly: true
          description: >-
            The end user of the session, set by OTel ingest from the first trace
            that names one. Read-only.
          example: customer_42
        createdAt:
          type: string
          format: date-time
        deletedAt:
          type: string
          format: date-time
          nullable: true
      required:
        - id
        - customId
        - versionId
        - userId
        - testCaseId
        - context
        - stoppingReason
        - recordingUri
        - error
        - status
        - isProduction
        - isSeed
        - runId
        - endUser
        - deletedAt
    Error:
      type: object
      properties:
        error:
          type: string
          example: NotFound
          description: >-
            The HTTP status name in PascalCase, such as `BadRequest` or
            `NotFound`.
        message:
          type: string
          example: Product not found
          description: What went wrong, for a person.
      required:
        - error
        - message
    Prefer:
      type: string
      description: >-
        Send `return=minimal` to get no body back from a write and skip reading
        the resource: a create answers `201` with only `Location`, and an update
        answers `204`.
      example: return=minimal
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        API key authorization. Pass your API key in the Authorization header as
        a Bearer token. Both new (`gsk_*`) and legacy (`gsk-`) API keys are
        accepted, e.g. `Authorization: Bearer gsk_...` or `Authorization: Bearer
        gsk-...`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.