---
title: "Create Context"
method: POST
path: "/v0/project/{project_name}/contexts"
tags: ["Contexts"]
---

# Create Context

`POST /v0/project/{project_name}/contexts`

Creates one or more contexts within a project. Contexts can be used to organize logs
and artifacts within a project.

If is_versioned=True, all logs in this context will be versioned and mutable.
The context version will increment automatically when logs are added, updated, or removed.

The context can be provided as:
- A string (which will be used as the name with no description)
- A ContextCreateRequest object with name and description fields
- A list of strings for batch creation
- A list of ContextCreateRequest objects for batch creation

## Path parameters

- `project_name` string, required — Name of the project to create context in.

## Request body

- union
  - ContextCreateRequest — Request model for creating a new context within a project.
    - `name` string, required — Context name, can be nested using '/' (e.g., 'parent/child'). Must contain only alphanumeric characters, underscores, and hyphens.
    - `description` string, nullable — Optional description of the context
    - `is_versioned` boolean — Whether the context should be versioned. If True, the context will be versioned and mutable.
    - `allow_duplicates` boolean — Whether duplicate log entries are allowed in this context. If False, attempts to add duplicate logs will be ignored.
    - `unique_keys` object, nullable — Unique key definition. Keys are column names, values are types ('str', 'int', 'float', 'bool', 'datetime', 'time', 'date', 'timedelta', 'dict', 'list').
    - `auto_counting` object, nullable — Auto-counting configuration. Keys are column names to auto-increment, values are parent counter names (None for independent counters).
    - `foreign_keys` ForeignKeyConfig[], nullable — Foreign key definitions for referential integrity
      - `name` string, required — Column name or path to nested field that references another context. Supports: - Simple column: 'department_id' - Array elements: 'images[*].image_id' - Nested object: 'metadata.user.user_id' - Mixed nesting: 'teams[*].members[*].user_id'
      - `references` string, required — Referenced context and column in format 'ContextName.column_name'
      - `on_delete` 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION' — Action to perform when referenced row is deleted
      - `on_update` 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION' — Action to perform when referenced row is updated
      - `default` unknown
      - `is_nested` boolean, nullable — Auto-set: True if this FK uses a nested path (contains . or [])
      - `path_segments` object[], nullable — Auto-set: Parsed path structure for nested FKs
  - string
  - union[]
    - union
      - ContextCreateRequest — Request model for creating a new context within a project.
        - `name` string, required — Context name, can be nested using '/' (e.g., 'parent/child'). Must contain only alphanumeric characters, underscores, and hyphens.
        - `description` string, nullable — Optional description of the context
        - `is_versioned` boolean — Whether the context should be versioned. If True, the context will be versioned and mutable.
        - `allow_duplicates` boolean — Whether duplicate log entries are allowed in this context. If False, attempts to add duplicate logs will be ignored.
        - `unique_keys` object, nullable — Unique key definition. Keys are column names, values are types ('str', 'int', 'float', 'bool', 'datetime', 'time', 'date', 'timedelta', 'dict', 'list').
        - `auto_counting` object, nullable — Auto-counting configuration. Keys are column names to auto-increment, values are parent counter names (None for independent counters).
        - `foreign_keys` ForeignKeyConfig[], nullable — Foreign key definitions for referential integrity
          - `name` string, required — Column name or path to nested field that references another context. Supports: - Simple column: 'department_id' - Array elements: 'images[*].image_id' - Nested object: 'metadata.user.user_id' - Mixed nesting: 'teams[*].members[*].user_id'
          - `references` string, required — Referenced context and column in format 'ContextName.column_name'
          - `on_delete` 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION' — Action to perform when referenced row is deleted
          - `on_update` 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'RESTRICT' | 'NO ACTION' — Action to perform when referenced row is updated
          - `default` unknown
          - `is_nested` boolean, nullable — Auto-set: True if this FK uses a nested path (contains . or [])
          - `path_segments` object[], nullable — Auto-set: Parsed path structure for nested FKs
      - string
      - object

## Response `200`

Successful Response

- unknown

## Other responses

- `400` — Bad Request
- `404` — Project Not Found
- `422` — Validation Error

---

[API](https://skmtc.net/unify/apis/unifyai-http-api-reference.md) · [All operations](https://skmtc.net/unify/apis/unifyai-http-api-reference/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/unify/unifyai-http-api-reference/revisions/900377f918b6/schema)
