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

# Create a new session

> Create a new player session for a specific game. A session ties a player to a game context and is used for tracking interactions & specific context.




## OpenAPI

````yaml /api-reference/openapi.yaml post /sessionmanager
openapi: 3.0.3
info:
  title: NPC Builder - API
  description: >
    This is the latest NPC Builder API specification that defines a
    comprehensive, production-ready API for NPC Builder. The API is divided into
    three primary services:


    **Interactions Service**  
      - **Purpose:** Enables dynamic, context-aware conversations between players and NPC characters.


    **Context Service**  
      - **Purpose:** Manages in-game entities to build and maintain immersive game environments.
      - **Includes:**  
        - **Worlds:** Create, update, and delete game worlds.
        - **Regions:** Define and manage distinct regions within a world.
        - **Locations:** Handle specific locations within regions.
        - **Characters:** Manage the lifecycle (creation, updating, deletion) of NPC characters.


    **Sessions Service**  
      - **Purpose:** Manages player sessions to maintain game context and track interactions.


    Overall, this specification serves as a detailed guide to leveraging NPC
    Builder’s services—empowering developers to build rich, interactive
    experiences while efficiently managing game contexts and entities.
        _You must stick to the data structure defined, otherwise you may encounter unhandled errors_


    **Please check the schemas of each request to find the allowed values for
    certain properties.**


    _Technical Limitations: Character's knowledge and relationships updating and
    deleting are not available through the API. They must be managed through our
    app's frontend._


    Some useful links:

    - [Our website](https://npcbuilder.com)

    - [The App](https://app.npcbuilder.com)
  termsOfService: https://npcbuilder.com/terms-and-conditions/
  contact:
    email: support@npcbuilder.com
  version: 1.6.0
servers:
  - url: https://app.npcbuilder.com/api
    description: Production API for context, sessions, and non-interaction endpoints
security: []
tags:
  - name: Interactions
    description: Manage your NPCs text conversations and interactive responses.
  - name: Characters
    description: Manage characters in your game including creation, update, and deletion.
  - name: Worlds
    description: Create and manage immersive worlds for your game.
  - name: Regions
    description: Define and manage regions within your worlds.
  - name: Locations
    description: Manage specific locations within regions of your game.
  - name: Sessions
    description: Create, retrieve, and delete player sessions for enhanced game management.
paths:
  /sessionmanager:
    post:
      tags:
        - Sessions
      summary: Create a new session
      description: >
        Create a new player session for a specific game. A session ties a player
        to a game context and is used for tracking interactions & specific
        context.
      requestBody:
        required: true
        description: The session details required to create a new session.
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SessionRequest'
      responses:
        '200':
          description: Session created successfully.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Confirmation message including session details.
                    example: >-
                      Session created for key: campaign_nightfall with id:
                      ABC123 has been created
                  session_key:
                    type: string
                  session_id:
                    type: string
                  player_id:
                    type: string
                    format: uuidv4
        '400':
          description: >
            Validation error – The session request payload did not meet the
            required schema.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '409':
          description: Conflict – Session already exists.
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    description: Message indicating the session already exists.
                    example: >-
                      Session already existing for key: campaign_nightfall.
                      Please delete it before creating a new one.
                  session_id:
                    type: string
        '500':
          description: >
            Internal Server Error – An error occurred while creating the
            session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - npcbuilder_auth: []
components:
  schemas:
    SessionRequest:
      type: object
      description: >
        Schema for creating a new session. Contains session key, game
        identifier, and player identifier.
      properties:
        session_key:
          type: string
          description: A unique key for the session.
          pattern: ^[a-zA-Z0-9_-]+$
          maxLength: 50
          example: campaign_nightfall
        game_id:
          type: string
          description: The unique identifier for the game.
          maxLength: 50
          example: game_12345
        player_id:
          type: string
          description: The unique identifier for the player.
          format: uuidv4
          example: 550e8400-e29b-41d4-a716-446655440000
      required:
        - session_key
        - game_id
        - player_id
    ErrorResponse:
      type: object
      description: Standard error response schema.
      properties:
        message:
          type: string
          description: Detailed error message.
          example: An error occurred
  securitySchemes:
    npcbuilder_auth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````