> ## 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.

# 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.



## OpenAPI

````yaml POST /api/experiment/init
openapi: 3.1.0
info:
  title: LangWatch API
  version: 1.0.0
  description: LangWatch openapi spec
servers:
  - url: https://app.langwatch.ai
security:
  - project_api_key: []
paths:
  /api/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.
      operationId: postApiExperimentInit
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                experiment_slug:
                  type: string
                  description: >-
                    Stable slug you choose. Reusing it returns the same
                    experiment instead of creating another, which is what makes
                    repeated runs land together.
                experiment_id:
                  type: string
                  description: Existing experiment id, as an alternative to the slug
                experiment_type:
                  type: string
                  enum:
                    - DSPY
                    - BATCH_EVALUATION
                    - BATCH_EVALUATION_V2
                  description: >-
                    BATCH_EVALUATION_V2 for SDK batch evaluations, DSPY for
                    optimizer runs
                experiment_name:
                  type: string
                  description: Display name, used only when the experiment is created
                workflowId:
                  type: string
                  description: Optimization Studio workflow this experiment belongs to
              required:
                - experiment_type
              anyOf:
                - required:
                    - experiment_slug
                - required:
                    - experiment_id
      responses:
        '200':
          description: The experiment, created or already existing
          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
        '400':
          description: >-
            The body was not valid JSON, or neither experiment_slug nor
            experiment_id was supplied
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    properties:
                      message:
                        type: string
                        description: Set when the body was not valid JSON
                    required:
                      - message
                  - type: object
                    properties:
                      error:
                        type: string
                        description: >-
                          The validation failure as a sentence, not a code:
                          neither identifier was supplied, or a field had the
                          wrong type
                    required:
                      - error
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                required:
                  - message
        '403':
          description: >-
            The API key lacks experiments:manage, or the plan's experiment limit
            is already reached
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Stable failure code; branch on this
                  message:
                    type: string
                  fault:
                    type: string
                    description: >-
                      Who the failure is attributable to: customer, platform,
                      provider
                  tips:
                    type: array
                    items:
                      type: string
                  docsUrl:
                    type: string
                  limitType:
                    type: string
                    description: Which plan limit was reached, on resource_limit_exceeded
                  current:
                    type: number
                    description: Experiments already in use
                  max:
                    type: number
                    description: What the plan allows
                required:
                  - error
                additionalProperties: true
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.

````