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

# Generate Protocol Endpoint

> Generate a UCP protocol from a natural-language description.

When the description leaves a value undecided that would change what runs
on the channel, the response carries ``questions`` and no protocol. Answer
them and call again with the full ``clarifications`` history.

Any protocol that *is* returned has already passed the same validation as
``POST /protocols/validate`` and contains no unresolved ``input["..."]``
references, so it can be saved as an experiment template directly.

Parameters
----------
body : GenerateProtocolRequest
    The natural-language prompt, any answers already given, and an
    optional existing protocol to edit rather than replace.

Returns
-------
GenerateProtocolResponse
    Either the generated YAML with a suggested name, an explanation, and
    the assumptions made — or the questions needed to write it.

Raises
------
ExternalServiceError
    If the model could not produce a valid protocol.



## OpenAPI

````yaml https://api.ionworks.com/openapi.json post /protocols/generate
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.ionworks.com
    description: Production
security: []
paths:
  /protocols/generate:
    post:
      tags:
        - protocols
      summary: Generate Protocol Endpoint
      description: >-
        Generate a UCP protocol from a natural-language description.


        When the description leaves a value undecided that would change what
        runs

        on the channel, the response carries ``questions`` and no protocol.
        Answer

        them and call again with the full ``clarifications`` history.


        Any protocol that *is* returned has already passed the same validation
        as

        ``POST /protocols/validate`` and contains no unresolved ``input["..."]``

        references, so it can be saved as an experiment template directly.


        Parameters

        ----------

        body : GenerateProtocolRequest
            The natural-language prompt, any answers already given, and an
            optional existing protocol to edit rather than replace.

        Returns

        -------

        GenerateProtocolResponse
            Either the generated YAML with a suggested name, an explanation, and
            the assumptions made — or the questions needed to write it.

        Raises

        ------

        ExternalServiceError
            If the model could not produce a valid protocol.
      operationId: generate_protocol_endpoint_protocols_generate_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateProtocolRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateProtocolResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    GenerateProtocolRequest:
      properties:
        prompt:
          type: string
          maxLength: 4000
          minLength: 1
          title: Prompt
          description: >-
            Plain-English description of the test to run, e.g. '1C/1C cycling
            for 200 cycles between 4.2 V and 2.5 V with 10-minute rests'.
        current_protocol:
          anyOf:
            - type: string
              maxLength: 100000
            - type: 'null'
          title: Current Protocol
          description: >-
            Optional existing protocol as UCP YAML. When supplied the prompt is
            treated as an edit to it rather than a fresh protocol.
        clarifications:
          items:
            $ref: '#/components/schemas/ClarificationAnswer'
          type: array
          maxItems: 20
          title: Clarifications
          description: >-
            Answers to questions a previous call returned, oldest first. Send
            the full history each time — the exchange is stateless.
        cell_specification_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Cell Specification Id
          description: >-
            Cell the test will run on. Its voltage limits, capacity and rate
            limits are given to the generator as facts, so it stops guessing (or
            asking) about them.
        skip_existing:
          type: boolean
          title: Skip Existing
          description: >-
            Skip the saved-protocol search and write a new protocol. Set when
            the user rejects the suggested matches.
          default: false
      type: object
      required:
        - prompt
      title: GenerateProtocolRequest
      description: Request body for generating a protocol from natural language.
    GenerateProtocolResponse:
      properties:
        protocol_yaml:
          type: string
          title: Protocol Yaml
          default: ''
        name:
          type: string
          title: Name
          default: ''
        explanation:
          type: string
          title: Explanation
          default: ''
        assumptions:
          items:
            type: string
          type: array
          title: Assumptions
        questions:
          items:
            $ref: '#/components/schemas/ClarifyingQuestionResponse'
          type: array
          title: Questions
        matches:
          anyOf:
            - $ref: '#/components/schemas/ExistingProtocolMatchResponse'
            - type: 'null'
      type: object
      title: GenerateProtocolResponse
      description: |-
        A protocol, the questions needed to write one, or an existing match.

        Exactly one branch is populated. Callers should check ``questions`` and
        ``matches`` before reading ``protocol_yaml`` — both leave it empty.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ClarificationAnswer:
      properties:
        question:
          type: string
          maxLength: 2000
          title: Question
        answer:
          type: string
          maxLength: 4000
          title: Answer
      type: object
      required:
        - question
        - answer
      title: ClarificationAnswer
      description: One question the user has already answered.
    ClarifyingQuestionResponse:
      properties:
        question:
          type: string
          title: Question
        why:
          type: string
          title: Why
          default: ''
        options:
          items:
            type: string
          type: array
          title: Options
      type: object
      required:
        - question
      title: ClarifyingQuestionResponse
      description: A question the user must answer before the protocol can be written.
    ExistingProtocolMatchResponse:
      properties:
        template_ids:
          items:
            type: string
          type: array
          title: Template Ids
        note:
          type: string
          title: Note
          default: ''
      type: object
      required:
        - template_ids
      title: ExistingProtocolMatchResponse
      description: A saved protocol that already does what was asked for.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````