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

# Create context

> Create a new context. Optionally copy from an existing context using the `from` parameter, and specify a `version` to fork from a specific version.

> [!TIP]
>
> Use `from` with `version`, `at`, or `before` to fork from a specific point in history. Learn more in the [Fork & Clone Contexts](https://ultracontext.ai/docs/guides/fork-clone-contexts.md) guide.


## OpenAPI

````yaml /api-reference/openapi.json post /contexts
openapi: 3.1.0
info:
  title: UltraContext
  description: >-
    Manage conversation contexts with automatic versioning. Every mutation
    creates a new branch, preserving full history.
  version: 1.1.0
servers:
  - url: https://api.ultracontext.ai
security:
  - bearerAuth: []
paths:
  /contexts:
    post:
      summary: Create context
      description: >-
        Create a new context. Optionally copy from an existing context using the
        `from` parameter, and specify a `version` to fork from a specific
        version.
      operationId: createContext
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateContextInput'
      responses:
        '201':
          description: Context created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Context'
        '400':
          description: Invalid index (when using `at` with `from`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Version not found (when using `version` with `from`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      x-codeSamples:
        - lang: typescript
          label: TypeScript
          source: >-
            const ctx = await uc.create()


            // With metadata

            const ctx = await uc.create({ metadata: { name: 'my-session' } })


            // Copy from existing (latest version)

            const fork = await uc.create({ from: 'ctx_abc123' })


            // Fork from specific version

            const v1Fork = await uc.create({ from: 'ctx_abc123', version: 1 })


            // Fork at specific message index

            const partial = await uc.create({ from: 'ctx_abc123', at: 5 })


            // Fork from point-in-time

            const snapshot = await uc.create({ from: 'ctx_abc123', before:
            '2024-01-15T10:30:00Z' })
        - lang: python
          label: Python
          source: >-
            ctx = uc.create()


            # With metadata

            ctx = uc.create(metadata={'name': 'my-session'})


            # Copy from existing (latest version)

            fork = uc.create(from_='ctx_abc123')


            # Fork from specific version

            v1_fork = uc.create(from_='ctx_abc123', version=1)


            # Fork at specific message index

            partial = uc.create(from_='ctx_abc123', at=5)


            # Fork from point-in-time

            snapshot = uc.create(from_='ctx_abc123',
            before='2024-01-15T10:30:00Z')
        - lang: bash
          label: cURL
          source: |-
            curl -X POST https://api.ultracontext.ai/contexts \
              -H "Authorization: Bearer $API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"metadata": {"name": "my-session"}}'

            # Fork from specific version
            curl -X POST https://api.ultracontext.ai/contexts \
              -H "Authorization: Bearer $API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"from": "ctx_abc123", "version": 1}'

            # Fork from point-in-time
            curl -X POST https://api.ultracontext.ai/contexts \
              -H "Authorization: Bearer $API_KEY" \
              -H "Content-Type: application/json" \
              -d '{"from": "ctx_abc123", "before": "2024-01-15T10:30:00Z"}'
components:
  schemas:
    CreateContextInput:
      type: object
      properties:
        from:
          type: string
          description: Source context ID to copy from (optional)
        version:
          type: integer
          description: >-
            When forking with `from`, copy from this specific version
            (0-indexed)
        at:
          type: integer
          description: When forking with `from`, copy only messages 0 through this index
        before:
          type: string
          format: date-time
          description: >-
            When forking with `from`, copy point-in-time state before this ISO
            timestamp
        metadata:
          type: object
          additionalProperties: true
          description: User-defined metadata for this context
      description: Create a new context with optional fork params and metadata
    Context:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier (ctx_...)
          example: ctx_a1b2c3d4e5f6
        metadata:
          type: object
          description: User-defined metadata
          additionalProperties: true
        created_at:
          type: string
          format: date-time
          description: ISO 8601 timestamp
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key from your UltraContext dashboard

````

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