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

# Create New Experiment

> Create an experiment or return the existing experiment with the same name.

Use this tool when starting a new MCP workflow namespace and you need an
``experiment_id`` for later circuit, job, or artifact calls. Name matching
is exact within the authenticated user scope, so the endpoint may return an
existing experiment instead of inserting a new one.

When to Use:
    - Call this at the start of a new workflow when later tool calls need
      a stable ``experiment_id``.
    - Call this when the user has a preferred experiment name and wants to
      reuse the existing experiment if it already exists.

Constraints:
    - Name matching is exact and scoped to the authenticated user.
    - The route may return an existing experiment instead of inserting a
      new one.

Notes:
    - The response is the full ``ContextExperimentModel`` object, not a
      lightweight acknowledgment wrapper.
    - For agent-facing output, surface ``id`` and ``name`` first, then
      summarize the context or description in one short line.

Args:
    user: Authenticated user resolved from the API key.
    data: Experiment payload containing the requested name plus optional
        description and MCP context.
    db: Active database session.

Returns:
    The created or reused experiment object for the caller scope.



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json post /ai/create_new_experiment
openapi: 3.1.0
info:
  title: Haiqu API
  summary: Haiqu RESTful API service.
  description: Cloud service providing the access to Haiqu cloud runtime
  contact:
    name: Haiqu Inc.
    url: https://haiqu.ai/
    email: info@haiqu.ai
  version: 1.4.0
servers: []
security: []
paths:
  /ai/create_new_experiment:
    post:
      summary: Create New Experiment
      description: >-
        Create an experiment or return the existing experiment with the same
        name.


        Use this tool when starting a new MCP workflow namespace and you need an

        ``experiment_id`` for later circuit, job, or artifact calls. Name
        matching

        is exact within the authenticated user scope, so the endpoint may return
        an

        existing experiment instead of inserting a new one.


        When to Use:
            - Call this at the start of a new workflow when later tool calls need
              a stable ``experiment_id``.
            - Call this when the user has a preferred experiment name and wants to
              reuse the existing experiment if it already exists.

        Constraints:
            - Name matching is exact and scoped to the authenticated user.
            - The route may return an existing experiment instead of inserting a
              new one.

        Notes:
            - The response is the full ``ContextExperimentModel`` object, not a
              lightweight acknowledgment wrapper.
            - For agent-facing output, surface ``id`` and ``name`` first, then
              summarize the context or description in one short line.

        Args:
            user: Authenticated user resolved from the API key.
            data: Experiment payload containing the requested name plus optional
                description and MCP context.
            db: Active database session.

        Returns:
            The created or reused experiment object for the caller scope.
      operationId: create_new_experiment
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContextExperimentSubmitModel'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContextExperimentModel'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    ContextExperimentSubmitModel:
      properties:
        name:
          type: string
          title: Name
          description: >-
            Experiment name. Matching is exact within the authenticated user
            scope.
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: >-
            Experiment description stored as HTML-formatted text. Send markup
            such as `<p>...</p>` when structure or rich text is needed.
          default: ''
        context:
          anyOf:
            - type: string
            - type: 'null'
          title: Context
          default: ''
      type: object
      required:
        - name
      title: ContextExperimentSubmitModel
      description: |-
        Define payload for MCP experiment creation requests.

        Attributes:
            name: Experiment name unique within the caller scope.
            description: Optional HTML-formatted description persisted by the API.
            context: ai rationale for creating this experiment.
      examples:
        - context: >-
            Create an experiment bucket for Bell-state runs and follow-up
            artifacts.
          description: <p>Baseline benchmark for simulator and QPU runs.</p>
          name: Bell-state benchmark
    ContextExperimentModel:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          default: ''
        creation_date:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Creation Date
        tags:
          anyOf:
            - type: string
            - type: 'null'
          title: Tags
          default: ''
        circuits_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Circuits Count
          default: 0
        jobs_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Jobs Count
          default: 0
        last_action_date:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Last Action Date
        context:
          type: string
          title: Context
        url:
          anyOf:
            - type: string
            - type: 'null'
          title: Url
          default: ''
      type: object
      required:
        - id
        - name
        - context
      title: ContextExperimentModel
      description: |-
        Represent an experiment with MCP-specific context metadata.

        ``description`` and ``creation_date`` remain optional for compatibility
        with legacy database rows.

        Attributes:
            description: Plain-text experiment description. Optional for legacy
                rows that still store ``NULL``.
            creation_date: Experiment creation timestamp. Optional for legacy rows
                that still store ``NULL``.
            context: Additional plain-text guidance for AI agents consuming the
                experiment.
            url: Dashboard URL for the experiment when available.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    APIKeyQuery:
      type: apiKey
      in: query
      name: HAIQU_API_KEY
    APIKeyHeader:
      type: apiKey
      in: header
      name: authorization

````