openapi: 3.1.0
info:
  title: AgenticNode Prompt Registry Runtime API
  version: "1.0.0"
  description: >
    Fetch a deployed prompt version by slug at runtime, decoupling prompt
    changes from code deploys. Authenticate with a runtime API token minted
    under /prompts/tokens (pk_...). CORS-open for GET so it can be called
    directly from browsers and edge runtimes.
servers:
  - url: https://agenticnode.io
security:
  - bearerAuth: []
paths:
  /api/v1/prompts/{slug}:
    get:
      operationId: getPrompt
      summary: Fetch the deployed prompt content (unrendered)
      parameters:
        - $ref: '#/components/parameters/slug'
        - $ref: '#/components/parameters/environment'
        - $ref: '#/components/parameters/version'
      responses:
        '200':
          description: The resolved prompt version.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Prompt'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/v1/prompts/{slug}/render:
    post:
      operationId: renderPrompt
      summary: Fetch the deployed prompt with {{variables}} substituted server-side
      parameters:
        - $ref: '#/components/parameters/slug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                environment:
                  type: string
                  description: Defaults to "production".
                version:
                  type: integer
                  description: Pins an exact version, bypassing the environment's deployed pointer.
                variables:
                  type: object
                  additionalProperties: true
                  description: Values substituted into {{variable}} placeholders.
      responses:
        '200':
          description: The rendered prompt.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RenderedPrompt'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Runtime API token (pk_...), or pass as `X-Api-Key`.
  parameters:
    slug:
      name: slug
      in: path
      required: true
      schema:
        type: string
    environment:
      name: environment
      in: query
      required: false
      schema:
        type: string
        default: production
    version:
      name: version
      in: query
      required: false
      schema:
        type: integer
  responses:
    Unauthorized:
      description: Missing or invalid API token.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: No prompt with that slug, or no deployment for the requested environment.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
    Prompt:
      type: object
      properties:
        slug: { type: string }
        name: { type: string }
        environment: { type: string, nullable: true }
        version: { type: integer }
        content: { type: string }
        variables:
          type: array
          items: { type: string }
        model: { type: string, nullable: true }
        params:
          type: object
          additionalProperties: true
        updated_at: { type: string, format: date-time }
    RenderedPrompt:
      type: object
      properties:
        slug: { type: string }
        environment: { type: string, nullable: true }
        version: { type: integer }
        model: { type: string, nullable: true }
        params:
          type: object
          additionalProperties: true
        rendered: { type: string }
        missing_variables:
          type: array
          items: { type: string }
