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

# Generate Script from Prompt

> Submits a natural language prompt to the AI engine to generate a MikroTik RouterOS script. The response includes the generated script content, a flag indicating if the script is potentially destructive, and any errors or warnings from the AI.



## OpenAPI

````yaml /api/en/scripts.yaml post /scripts/gen-ai
openapi: 3.0.3
info:
  title: Altostrat Scripts API
  version: 1.0.0
  description: >-
    The Altostrat Scripts API is the microservice responsible for creating,
    managing, and executing MikroTik RouterOS scripts across your network
    infrastructure.


    It serves as the core automation engine within the Altostrat SDX platform,
    empowering developers to programmatically deploy configuration changes,
    perform operational tasks, and leverage AI for script generation. This API
    is the foundation for network automation and agentic AI capabilities.


    This API allows you to programmatically manage:

    - **Scheduled Scripts:** The primary resource for defining a script, its
    target devices, and a future execution time, complete with authorization
    workflows and progress tracking.

    - **Script Templates:** Reusable, version-controlled script blueprints that
    can be either private to an organization or shared globally to enforce
    standardization and best practices.

    - **Community Scripts:** A curated and searchable library of publicly
    available RouterOS scripts sourced from GitHub, providing ready-to-use
    solutions for common networking tasks.

    - **AI Script Generation:** An agentic AI endpoint that translates natural
    language prompts into functional and safe MikroTik RouterOS scripts.


    Developers use this API to build powerful, scalable, and intelligent network
    automation workflows for their fleet of MikroTik devices.
servers:
  - url: https://v1.api.altostrat.io
security:
  - BearerAuth:
      - script:view
      - script:create
      - script:update
      - script:delete
      - script:run
      - script:authorize
tags:
  - name: Scheduled Scripts
    description: >-
      Manage the lifecycle of scripts scheduled for execution on network
      devices.
  - name: Script Templates
    description: Create and manage reusable script templates for standardization.
  - name: Community Scripts
    description: Discover and utilize scripts from the public community repository.
  - name: AI Script Generation
    description: Generate MikroTik scripts from natural language prompts.
paths:
  /scripts/gen-ai:
    post:
      tags:
        - AI Script Generation
      summary: Generate Script from Prompt
      description: >-
        Submits a natural language prompt to the AI engine to generate a
        MikroTik RouterOS script. The response includes the generated script
        content, a flag indicating if the script is potentially destructive, and
        any errors or warnings from the AI.
      operationId: generateScriptFromAI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                prompt:
                  type: string
                  maxLength: 200
                  description: The natural language prompt describing the desired script.
                  example: >-
                    Create a firewall rule to block all incoming traffic on port
                    22 from the internet.
      responses:
        '200':
          description: The AI-generated script and analysis.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiScriptResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    AiScriptResponse:
      type: object
      properties:
        response:
          type: array
          items:
            type: object
            properties:
              content:
                type: string
                description: The generated MikroTik RouterOS script.
                example: >-
                  /ip firewall filter add action=drop chain=input
                  in-interface=ether1 protocol=tcp dst-port=22;
              error:
                type: string
                nullable: true
                description: Any errors or warnings identified by the AI during generation.
                example: null
              destructive:
                type: boolean
                description: >-
                  A flag indicating if the command has the potential to cause a
                  loss of connectivity or other destructive side effects.
                example: true
        tokenUsage:
          type: object
          properties:
            prompt:
              type: integer
              example: 75
            completion:
              type: integer
              example: 30
            total:
              type: integer
              example: 105
        response_id:
          type: string
          example: cmpl-8fV3x5m7y6z4w3v2u1t0s
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          description: A broad category for the error (e.g., 'invalid_request_error').
          example: invalid_request_error
        code:
          type: string
          description: A short, unique string identifying the specific error.
          example: parameter_missing
        message:
          type: string
          description: A human-readable description of what went wrong.
          example: The 'name' parameter is required for this request.
        doc_url:
          type: string
          description: >-
            A direct link to the documentation page for this specific error
            code.
          example: https://docs.altostrat.io/errors/parameter_missing
  responses:
    BadRequest:
      description: Bad Request - The request was malformed or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: >-
        Unauthorized - The request requires authentication and a valid Bearer
        token was not provided.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: >-
        Forbidden - The authenticated user does not have the required
        permissions (scopes) to perform this action.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnprocessableEntity:
      description: >-
        Unprocessable Entity - The request was well-formed but was unable to be
        followed due to semantic errors (e.g., validation failure).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal Server Error - An unexpected error occurred on the server.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Altostrat SDX API uses JWT Bearer tokens for authentication. Obtain a
        token via the Authentication API and include it in the Authorization
        header as 'Bearer {token}'.

````