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

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.

# Create an experiment

> Create an experiment, or return the existing one when the slug is already taken. This is the first call in an experiment run: take the slug back, report results against it, and every run under that slug groups together in the app. The SDKs call this endpoint for you. The body carries `experiment_type` and at least one of `experiment_slug` (the stable slug you choose, which is what makes repeated runs land together) or `experiment_id`; `experiment_name` names it on creation and `workflowId` ties it to an Optimization Studio workflow.



## OpenAPI

````yaml POST /api/v1/experiment/init
openapi: 3.1.0
info:
  title: LangWatch API
  description: LangWatch openapi spec
  version: 1.0.0
servers:
  - url: https://app.langwatch.ai
security:
  - project_api_key: []
paths:
  /api/v1/experiment/init:
    post:
      tags:
        - Experiments
      summary: Create an experiment
      description: >-
        Create an experiment, or return the existing one when the slug is
        already taken. This is the first call in an experiment run: take the
        slug back, report results against it, and every run under that slug
        groups together in the app. The SDKs call this endpoint for you. The
        body carries `experiment_type` and at least one of `experiment_slug`
        (the stable slug you choose, which is what makes repeated runs land
        together) or `experiment_id`; `experiment_name` names it on creation and
        `workflowId` ties it to an Optimization Studio workflow.
      operationId: postApiExperimentInit
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                experiment_id:
                  type:
                    - string
                    - 'null'
                experiment_slug:
                  type:
                    - string
                    - 'null'
                experiment_type:
                  type: string
                  enum:
                    - DSPY
                    - BATCH_EVALUATION
                    - BATCH_EVALUATION_V2
                experiment_name:
                  type: string
                workflowId:
                  type: string
              required:
                - experiment_type
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                    description: Slug of the experiment, created or existing
                  path:
                    type: string
                    description: Path to the experiment in the LangWatch app
                required:
                  - slug
                  - path
                additionalProperties: false
        '400':
          description: The body was not valid JSON
          content: {}
        '401':
          description: Missing or invalid API key
          content: {}
        '403':
          description: >-
            The API key lacks experiments:manage, or the plan's experiment limit
            is already reached
          content: {}
        '413':
          description: The body is larger than the deployment accepts
          content: {}
        '422':
          description: >-
            The body failed validation, or neither experiment_slug nor
            experiment_id was supplied
          content: {}
      security:
        - project_api_key: []
components:
  securitySchemes:
    project_api_key:
      type: apiKey
      in: header
      name: X-Auth-Token
      description: >-
        Project API key for sending traces and accessing project-scoped
        resources. Format: sk-lw-... (no underscore). Obtain one by creating a
        project via the Admin API or the LangWatch UI.

````

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