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

# Get Haiqu Algorithm Recipe

> Return a complete, runnable Python script for one algorithm.

Use this tool when the user wants to run an algorithm, see its code, asks
"how do I run LR-QAOA", "give me the code", "show me a noise-mitigation
benchmark", or "benchmark this on a noisy device". Get the key from
``list_haiqu_algorithms`` first if the user did not give an exact one.

The returned ``code`` is self-contained: it runs the algorithm across four
variants (ideal baseline, noisy baseline, transpiled-on-Haiqu run, full
Haiqu stack with error mitigation) on one problem instance and prints an
approximation-ratio comparison. The user can run it as-is or edit the
clearly marked EDIT-HERE block (graph, layers, shots, device) to change
the problem. The two Haiqu variants require the user's Haiqu API key; the
two baselines run with only open-source packages.

Args:
    algorithm_key: Algorithm identifier from ``list_haiqu_algorithms``
        (e.g. "lr-qaoa").



## OpenAPI

````yaml https://api.haiqu.ai/openapi.json get /ai/qakb/algorithms/{algorithm_key}/recipe
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/qakb/algorithms/{algorithm_key}/recipe:
    get:
      summary: Get Haiqu Algorithm Recipe
      description: >-
        Return a complete, runnable Python script for one algorithm.


        Use this tool when the user wants to run an algorithm, see its code,
        asks

        "how do I run LR-QAOA", "give me the code", "show me a noise-mitigation

        benchmark", or "benchmark this on a noisy device". Get the key from

        ``list_haiqu_algorithms`` first if the user did not give an exact one.


        The returned ``code`` is self-contained: it runs the algorithm across
        four

        variants (ideal baseline, noisy baseline, transpiled-on-Haiqu run, full

        Haiqu stack with error mitigation) on one problem instance and prints an

        approximation-ratio comparison. The user can run it as-is or edit the

        clearly marked EDIT-HERE block (graph, layers, shots, device) to change

        the problem. The two Haiqu variants require the user's Haiqu API key;
        the

        two baselines run with only open-source packages.


        Args:
            algorithm_key: Algorithm identifier from ``list_haiqu_algorithms``
                (e.g. "lr-qaoa").
      operationId: get_haiqu_algorithm_recipe
      parameters:
        - name: algorithm_key
          in: path
          required: true
          schema:
            type: string
            title: Algorithm Key
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecipeResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - APIKeyQuery: []
        - APIKeyHeader: []
components:
  schemas:
    RecipeResponse:
      properties:
        algorithm:
          type: string
          title: Algorithm
          description: Algorithm key the recipe is for.
        language:
          type: string
          title: Language
          description: Source language of the recipe.
          default: python
        code:
          type: string
          title: Code
          description: Complete, copy-pasteable Python script. Runs locally and on Haiqu.
        note:
          type: string
          title: Note
          description: How to run it + which variants need a Haiqu API key.
        steps:
          items:
            $ref: '#/components/schemas/RecipeStep'
          type: array
          title: Steps
          description: >-
            Ordered demo plan. The orchestrating LLM should walk these in order,
            rendering the indicated artifacts inline. The plan is
            algorithm-agnostic in shape; algorithm-specific render content comes
            from sandbox-side hooks the recipe defines (``compute_results``,
            ``format_headline``).
      type: object
      required:
        - algorithm
        - code
        - note
      title: RecipeResponse
      description: |-
        A self-contained, runnable Python script for one algorithm,
        plus a per-algorithm demo orchestration plan.
      examples:
        - algorithm: lr-qaoa
          code: |
            from qiskit import QuantumCircuit
            # ... verified internals inlined here ...
            MANIFEST = {'algorithm': 'lr-qaoa', 'n_qubits': 8, 'qasm': '...'}
          language: python
          note: >-
            Run: pip install qiskit qiskit-aer qiskit-ibm-runtime networkx
            numpy; python the_file.py. The haiqu_run + haiqu_full variants
            additionally need `pip install haiqu-sdk` and HAIQU_API_KEY; the two
            baselines run without them.
          steps:
            - id: show_recipe
              intent: User reads what is about to execute before any side effects.
              render_after: []
              render_before:
                - Paste the `code` field as a fenced Python block.
                - Point out the EDIT-HERE region.
              title: Show the recipe code
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    RecipeStep:
      properties:
        id:
          type: string
          title: Id
          description: >-
            Stable step identifier (e.g. 'show_recipe', 'exec_recipe',
            'submit_baseline_ideal'). The orchestrating LLM uses these to track
            progress and reference steps in subsequent turns.
        title:
          type: string
          title: Title
          description: Short human-readable title.
        intent:
          type: string
          title: Intent
          description: One-sentence explanation of why this step exists.
        render_before:
          items:
            type: string
          type: array
          title: Render Before
          description: >-
            Discrete items to render in chat BEFORE the step's tool call. Each
            item is one instruction (a code block to paste, a tool payload to
            render, etc.).
        render_after:
          items:
            type: string
          type: array
          title: Render After
          description: >-
            Discrete items to render AFTER the step's tool call returns. Include
            the experiment dashboard URL on every step that touches an
            experiment so the user can drill in mid-run.
      type: object
      required:
        - id
        - title
        - intent
      title: RecipeStep
      description: |-
        One step in the demo orchestration plan returned alongside a recipe.

        The orchestrating LLM walks ``RecipeResponse.steps`` in order. For each
        step it renders the ``render_before`` items, makes any tool call implied
        by the step, then renders the ``render_after`` items. Algorithm-specific
        content (top bitstrings vs. decoded string vs. expectation value) is not
        encoded here; the step instructions point the LLM at sandbox-side hooks
        (``compute_results``, ``format_headline``) that each recipe defines.
    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

````