# Create (Token Auth)

> For AI agents: the complete documentation index is at https://buddy.works/llms.txt

`POST /unit-tests/sessions`

Add a new test session using suite token authentication

## Body Parameters

```typescript
interface BodyParameters {
  /** CI provider that initiated the test session */
  ci_provider?: "NONE" | "BUDDY" | "GITHUB_ACTION" | "CIRCLE_CI";
  /** URL to the external CI/CD run */
  ci_run_url?: string;
  /** Ending revision/commit hash for the test range */
  revision?: string;
  /** Type of Git reference */
  ref_type?: "BRANCH" | "TAG" | "PULL_REQUEST";
  /** Name of the Git reference (branch name, tag name, etc.). May be null if ref_type is not provided. */
  ref_name?: string;
  /** External CI/CD run identifier (e.g., GitHub Actions run ID) */
  run_id?: string;
  /** User/member reference */
  created_by?: MemberIdRequest;
  /** Execution hash ID. Set when session is a result of BUDDY action execution */
  execution_id?: string;
  /** Action execution hash ID. Set when session is a result of BUDDY action execution */
  action_execution_id?: string;
}
```

## Response Body

```typescript
interface ResponseBody {
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** Unique identifier of the test session */
  id?: string;
  /** Sequential ID within the suite */
  relative_id?: number;
  /** Timestamp when the session was created */
  create_date?: string;
  /** Timestamp when the session started */
  start_date?: string;
  /** Timestamp when the session finished */
  finish_date?: string;
  /** User/member reference */
  created_by?: MemberView;
  /** CI provider that initiated the test session */
  ci_provider?: "NONE" | "BUDDY" | "GITHUB_ACTION" | "CIRCLE_CI";
  /** URL to the external CI/CD run */
  ci_run_url?: string;
  /** Ending revision/commit hash for the test range */
  revision?: string;
  /** Type of Git reference */
  ref_type?: "BRANCH" | "TAG" | "PULL_REQUEST";
  /** Name of the Git reference (branch name, tag name, etc.). May be null if ref_type is not provided. */
  ref_name?: string;
  /** Execution hash ID. Set when session is a result of BUDDY action execution */
  execution_id?: string;
  /** Action execution hash ID. Set when session is a result of BUDDY action execution */
  action_execution_id?: string;
  /** Current status of the session */
  status?: "IN_PROGRESS" | "SUCCESSFUL" | "ERROR" | "SKIPPED";
  /** Error message if the session failed. Set when status is ERROR. */
  error_message?: string;
  /** Total duration in seconds */
  duration?: number;
  /** Total number of tests */
  tests_count?: number;
  /** Number of failed tests */
  failed_count?: number;
  /** Number of skipped tests */
  skipped_count?: number;
  /** Number of tests with errors */
  error_count?: number;
}
```

## Type Definitions

```typescript
interface MemberIdRequest {
  /** The ID of the user */
  id?: number;
}

interface MemberView {
  /** API endpoint to GET this object */
  url?: string;
  /** Web URL to view this object in Buddy.works */
  html_url?: string;
  /** The ID of the user */
  id?: number;
  /** The name of the user */
  name?: string;
  /** The unique username of the user */
  username?: string;
  /** The avatar URL of the user */
  avatar_url?: string;
  /** The email address of the user */
  email?: string;
  /** Whether the user has admin privileges */
  admin?: boolean;
  /** Whether the user is workspace owner */
  workspace_owner?: boolean;
}

```

## Request Example

```bash
curl -X POST "https://api.buddy.works/unit-tests/sessions" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
  "ci_provider": "GITHUB_ACTION",
  "revision": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1",
  "ref_type": "BRANCH",
  "ref_name": "main",
  "run_id": "12345678",
  "created_by": {
    "id": 123
  }
}'
```

## Response Example

**Status:** `201 Created`

```json
{
  "url": "https://api.buddy.works/workspaces/my-workspace/projects/my-project/unit-tests/suites/MNbyVedg/sessions/r4nBYXVq",
  "html_url": "https://app.buddy.works/my-workspace/my-project/unit-tests/MNbyVedg/r4nBYXVq",
  "id": "r4nBYXVq",
  "relative_id": 1,
  "create_date": "2025-10-21T06:42:08Z",
  "start_date": "2025-10-21T06:42:08Z",
  "created_by": {
    "url": "https://api.buddy.works/workspaces/my-workspace/members/1",
    "html_url": "https://app.buddy.works/my-workspace/-/profile/1",
    "id": 1,
    "name": "John Doe",
    "avatar_url": "https://app.buddy.works/image-server/user/0/0/0/0/0/0/1/d643744fbe5ebf2906a4d075a5b97110/w/32/32/AVATAR.png?ts=1760014081477",
    "email": "john.doe@company.com",
    "admin": true,
    "workspace_owner": true
  },
  "ci_provider": "BUDDY",
  "revision": "755b691cfff32e08aba35f2c9b1451ed76cfd583",
  "ref_type": "BRANCH",
  "ref_name": "master",
  "execution_id": "68f72b3d66907cbc77887986",
  "action_execution_id": "68f72b3d66907cbc77887988",
  "status": "SUCCESSFUL",
  "duration": 1,
  "tests_count": 109,
  "failed_count": 0,
  "skipped_count": 0,
  "error_count": 0
}
```

---
Original source: https://buddy.works/docs/api/unit-tests/sessions/create-token