> ## 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 to group traces.

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

## Returns

Returns a [Session](https://docs.galtea.ai/v5.14/concepts/product/version/session.md) object.

## Example

```python theme={"system"}
session = galtea.sessions.create(version_id=version_id, test_case_id=test_case_id, is_production=False)
```

## Parameters

**version\_id** `string`

The ID of the version to associate with this session.

> [!NOTE]
>
> Provide `version_id` or `product_id` (at least one). If both are given, `version_id` wins and `product_id` is ignored. Prefer `version_id` when you already have a specific version to attach to.

**product\_id** `string`

The ID of the product to associate with this session, as an alternative to `version_id`. The API resolves the product's latest version, or creates a default one if the product has none yet.

> [!NOTE]
>
> Provide `version_id` or `product_id` (at least one). If both are given, `version_id` wins and `product_id` is ignored.

**test\_case\_id** `string`

The ID of a test case. Forbidden when `is_production=True`. Sessions backed by a test case derive their `context` from the test case rather than the request.

**custom\_id** `string`

A client-provided custom ID for the session.

> [!NOTE]
>
> This is useful to associate sessions in the Galtea platform with those in your application.

**context** `string`

The context provided to the AI product during the session. Forbidden when `test_case_id` is set (it would be derived from the test case).

**is\_production** `boolean`

A flag to indicate if the session represents real production traffic. When omitted, the API derives it from `test_case_id` presence: no test case means production. A non-production session no longer requires a `test_case_id` — externally ingested sessions (e.g. imported traces) may be classified as development data without being linked to a test case.

**metadata** `object`

Arbitrary key/value metadata to attach to the session at creation time. Omit it to send no `metadata`. This is the same metadata you can later set with [Update Session](https://docs.galtea.ai/v5.14/sdk/api/session/update.md).

**run\_id** `string`

The [Run](https://docs.galtea.ai/v5.14/concepts/product/run.md) this session belongs to. Defaults to the run of the enclosing `galtea.runs.start()` block, when there is one. An explicit value wins over the block.

> [!NOTE]
>
> A production session belongs to no run, so the API refuses `run_id` when `is_production=True`.
> Inside a `galtea.runs.start()` block the SDK applies the same rule before the call: a production
> session joins no run, silently, instead of being refused. Pass `is_production=False` or a
> `test_case_id` to join the block.


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