{
  "openapi": "3.1.0",
  "info": {
    "title": "Smol Inference API",
    "version": "1.0"
  },
  "paths": {
    "/v2/organizations/{organization_id}/endpoints/{endpoint_id}/chat/completions": {
      "post": {
        "operationId": "createCompletion",
        "summary": "Create a chat completion",
        "description": "Submit one logical generation with your retained key. Returns a completion or, with stream: true, server-sent events.",
        "x-caller": "Endpoint credential or authorized Application",
        "security": [
          {
            "accessToken": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "organization_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "endpoint_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[!-~]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completion, or an SSE stream with stream enabled",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GatewayError"
                }
              }
            }
          }
        }
      }
    },
    "/v2/organizations/{organization_id}/endpoints/{endpoint_id}/requests/{request_id}": {
      "get": {
        "operationId": "readGatewayRequest",
        "summary": "Read gateway request status",
        "description": "Inspect retained status on the inference origin using the Smol request ID. This does not generate or replay an answer.",
        "x-caller": "Endpoint credential or authorized Application",
        "security": [
          {
            "accessToken": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "organization_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "endpoint_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "request_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Request status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "Request error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GatewayError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "accessToken": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "ChatMessage": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "role": {
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string",
            "minLength": 1,
            "maxLength": 16777216
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "ContextSelection": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "lineage_id": {
            "type": "string",
            "format": "uuid"
          },
          "handles": {
            "type": "array",
            "minItems": 1,
            "maxItems": 128,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "pattern": "^smol://v1/(?:text|json)/[0-9a-f]{64}$"
            }
          }
        },
        "required": [
          "lineage_id",
          "handles"
        ]
      },
      "ChatRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "model": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "messages": {
            "type": "array",
            "minItems": 1,
            "maxItems": 32,
            "items": {
              "$ref": "#/components/schemas/ChatMessage"
            }
          },
          "max_tokens": {
            "type": "integer",
            "minimum": 1,
            "maximum": 131072
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "temperature": {
            "type": [
              "number",
              "null"
            ],
            "minimum": 0,
            "maximum": 2
          },
          "top_p": {
            "type": [
              "number",
              "null"
            ],
            "exclusiveMinimum": 0,
            "maximum": 1
          },
          "smol_context": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/ContextSelection"
              },
              {
                "type": "null"
              }
            ]
          },
          "smol_context_mode": {
            "enum": [
              "none",
              null
            ]
          }
        },
        "required": [
          "model",
          "messages",
          "max_tokens"
        ],
        "not": {
          "required": [
            "smol_context",
            "smol_context_mode"
          ],
          "properties": {
            "smol_context": {
              "type": "object"
            },
            "smol_context_mode": {
              "const": "none"
            }
          }
        },
        "description": "System messages precede all conversation messages. Supply at least one user or assistant message. Endpoint profiles may have narrower limits."
      },
      "GatewayError": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "code": {
                "type": "string"
              }
            },
            "required": [
              "code"
            ]
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
