openapi: 3.1.0
info:
  title: CreatorNode Visual API — Render Code
  description: |
    Render source code to syntax-highlighted SVG or PNG using Shiki.

    100+ languages, VS Code themes, line highlighting, social media presets.
    Perfect for code cards, documentation images, and automated screenshots.
  version: 1.0.0
  contact:
    name: CreatorNode Support
    url: https://creatornode.io/support
  license:
    name: Proprietary
    url: https://creatornode.io/legal
servers:
  - url: https://api.creatornode.io/visual
    description: Production
tags:
  - name: Code
    description: Source code rendering endpoints
paths:
  /v1/render-code:
    post:
      operationId: renderCode
      tags:
        - Code
      summary: Render source code with syntax highlighting
      description: Render source code to syntax-highlighted SVG or PNG using Shiki.
        100+ languages supported. All VS Code themes available. Optional line
        highlighting for single lines, ranges, or combinations. Defaults to
        `responseFormat=json`; use `responseFormat=file` for raw SVG or PNG
        output.
      security:
        - ApiKey: []
        - {}
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RenderCodeRequest"
            examples:
              minimal:
                summary: Minimal request
                value:
                  responseFormat: json
                  code: |-
                    const greeting = 'Hello, World!';
                    console.log(greeting);
                  language: typescript
              withOptions:
                summary: With options
                value:
                  code: |-
                    def hello():
                        print('Hello!')

                    hello()
                  language: python
                  theme: github-dark
                  options:
                    lineNumbers: true
                    filename: hello.py
              withHighlighting:
                summary: Line highlighting
                value:
                  code: |-
                    function add(a, b) {
                      return a + b;
                    }

                    const result = add(2, 3);
                  language: javascript
                  options:
                    lineNumbers: true
                    highlightLines: 2,5
              pngOutput:
                summary: PNG output
                value:
                  responseFormat: file
                  code: |-
                    fn main() {
                        println!("Hello, Rust!");
                    }
                  language: rust
                  format: png
                  options:
                    preset: og
      responses:
        "200":
          description: Successful render (`json` by default, or raw SVG/PNG when
            `responseFormat=file`)
          headers:
            X-Processing-Time-Ms:
              description: Processing time in milliseconds
              schema:
                type: integer
            X-Cache-Hit:
              description: Whether result was from cache
              schema:
                type: boolean
            X-Credits-Used:
              description: Credits consumed by this request (present only for paid tiers)
              schema:
                type: integer
                example: 2
            X-Credits-Remaining:
              description: Remaining credits on the API key (present only for paid tiers with
                prepaid credits)
              schema:
                type: integer
            X-Content-Type-Options:
              description: Security header
              schema:
                type: string
                enum:
                  - nosniff
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RenderCodeResponse"
              example:
                success: true
                data: <svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 800 200'>...</svg>
                meta:
                  requestId: req_xyz789
                  format: svg
                  contentType: image/svg+xml
                  language: typescript
                  theme: github-dark
                  lineCount: 10
                  processingTimeMs: 82
                  cached: false
            image/svg+xml:
              schema:
                type: string
                format: binary
            image/png:
              schema:
                type: string
                format: binary
        "400":
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              examples:
                unsupportedLanguage:
                  summary: Unsupported language
                  value:
                    success: false
                    error:
                      code: UNSUPPORTED_LANGUAGE
                      message: "Unsupported language: xyz"
                    meta:
                      requestId: abc123
                codeTooLarge:
                  summary: Code too large
                  value:
                    success: false
                    error:
                      code: CODE_TOO_LARGE
                      message: Code exceeds size limit
                    meta:
                      requestId: abc123
                emptyCode:
                  summary: Empty code
                  value:
                    success: false
                    error:
                      code: EMPTY_CODE
                      message: Code cannot be empty
                    meta:
                      requestId: abc123
        "401":
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "429":
          description: Rate limited
          headers:
            Retry-After:
              description: Seconds until rate limit resets
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "503":
          description: Service temporarily saturated
          headers:
            Retry-After:
              description: Seconds before retrying the request
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                success: false
                error:
                  code: SERVICE_BUSY
                  message: Visual rendering service is temporarily saturated. Retry shortly.
                meta:
                  requestId: abc123
components:
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-API-Key
      description: APIM subscription key for authentication. Free tier available
        without key.
  schemas:
    RenderCodeRequest:
      type: object
      required:
        - code
        - language
      properties:
        responseFormat:
          type: string
          enum:
            - json
            - file
          default: json
          description: >
            Success response transport.

            - `json` (default): JSON wrapper with render metadata and optional
            recommendations.

            - `file`: raw SVG or PNG body with selected metadata in headers.
        code:
          type: string
          minLength: 1
          maxLength: 500000
          description: Source code to render
          example: |-
            const greeting = 'Hello!';
            console.log(greeting);
        language:
          type: string
          minLength: 1
          maxLength: 50
          description: |
            Programming language for syntax highlighting.

            Common languages: typescript, javascript, python, rust, go, java,
            csharp, cpp, ruby, php, swift, kotlin, sql, html, css, json, yaml,
            markdown, bash, powershell, shell, dockerfile, graphql, regex
          example: typescript
        format:
          type: string
          enum:
            - svg
            - png
          default: svg
          description: Output format (SVG or PNG)
        theme:
          type: string
          default: github-dark
          description: >
            VS Code theme name.


            Popular themes: github-light, github-dark, dracula, monokai, nord,

            one-dark-pro, vitesse-dark, vitesse-light, tokyo-night,
            material-theme
        options:
          $ref: "#/components/schemas/CodeOptions"
    CodeOptions:
      type: object
      description: Code rendering options
      properties:
        lineNumbers:
          type: boolean
          default: true
          description: Show line numbers
        highlightLines:
          type: string
          maxLength: 500
          description: |
            Lines to highlight. Formats:
            - Single: "5"
            - Multiple: "1,3,5"
            - Range: "1-5"
            - Combined: "1,3-5,10"
          example: 2-4,7
        filename:
          type: string
          maxLength: 255
          description: Optional filename to display as header
          example: main.ts
        tabSize:
          type: integer
          minimum: 1
          maximum: 8
          default: 2
          description: Tab width in spaces
        preset:
          type: string
          enum:
            - og
            - twitter
            - square
          description: |
            PNG size preset:
            - og: 1200x630 (Open Graph)
            - twitter: 1200x675 (Twitter card)
            - square: 1080x1080 (Instagram)
        width:
          type: integer
          minimum: 100
          maximum: 4096
          description: Custom width (overrides preset)
        height:
          type: integer
          minimum: 100
          maximum: 4096
          description: Custom height (overrides preset)
    RenderCodeResponse:
      type: object
      required:
        - success
        - data
        - meta
      properties:
        success:
          type: boolean
          enum:
            - true
        data:
          type: string
          description: |
            Rendered output:
            - SVG: Raw SVG string with embedded highlighting
            - PNG: Base64 encoded image
        meta:
          $ref: "#/components/schemas/CodeResponseMeta"
    CodeResponseMeta:
      type: object
      required:
        - requestId
        - format
        - contentType
        - language
        - theme
        - lineCount
        - processingTimeMs
      properties:
        requestId:
          type: string
          description: Unique request identifier
        format:
          type: string
          enum:
            - svg
            - png
          description: Artifact format selected by the request.
        contentType:
          type: string
          description: MIME type for the produced artifact.
        language:
          type: string
          description: Resolved language
        theme:
          type: string
          description: Resolved theme name
        lineCount:
          type: integer
          description: Number of lines in code
        processingTimeMs:
          type: integer
          description: Processing time in milliseconds
        cached:
          type: boolean
          description: Whether result was from cache
        sizeBytes:
          type: integer
          description: Size in bytes (PNG only)
    ErrorResponse:
      type: object
      required:
        - success
        - error
      properties:
        success:
          type: boolean
          const: false
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Machine-readable error code. See each endpoint for possible values.
            message:
              type: string
            details:
              type: object
              description: Additional context about the error (varies by endpoint).
              additionalProperties: true
        meta:
          type: object
          required:
            - requestId
          properties:
            requestId:
              type: string
            demoMode:
              type: boolean
              description: Whether this is a demo endpoint response
        recommendations:
          type: array
          items:
            $ref: "#/components/schemas/Recommendation"
    Recommendation:
      type: object
      required:
        - type
        - title
        - message
        - priority
      properties:
        type:
          type: string
          enum:
            - upgrade
            - tip
            - warning
        title:
          type: string
        message:
          type: string
        priority:
          type: string
          enum:
            - high
            - medium
            - low
        url:
          type: string
          format: uri
    RenderCodeDemoRequest:
      type: object
      required:
        - code
        - language
      properties:
        code:
          type: string
          minLength: 1
          description: |
            Source code to render. The demo endpoint returns a pre-built sample
            based on the theme type — it does not render your exact code.
          example: |-
            const greeting = 'Hello!';
            console.log(greeting);
        language:
          type: string
          minLength: 1
          description: Programming language (e.g., typescript, python, rust)
          example: typescript
        format:
          type: string
          enum:
            - svg
            - png
          default: svg
          description: Output format (determines which pre-built sample is returned)
        theme:
          type: string
          default: github-dark
          description: Theme name (dark themes return dark sample, light themes return
            light sample)
    RenderCodeDemoResponse:
      allOf:
        - $ref: "#/components/schemas/RenderCodeResponse"
        - type: object
          required:
            - demoMode
            - warning
          properties:
            demoMode:
              type: boolean
              enum:
                - true
              description: Always `true` — indicates this is demo data
            warning:
              type: string
              description: Human-readable notice that this is pre-built demo output
