{
  "openapi": "3.0.0",
  "info": {
    "title": "Ollama AI Provider API",
    "version": "2.0.0",
    "description": "RESTful API for interacting with Ollama AI models"
  },
  "servers": [
    {
      "url": "http://localhost:11434",
      "description": "Local Ollama server"
    }
  ],
  "paths": {
    "/api/generate": {
      "post": {
        "summary": "Generate completion",
        "operationId": "generate",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generation response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GenerateResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/chat": {
      "post": {
        "summary": "Chat completion",
        "operationId": "chat",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChatResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/models": {
      "get": {
        "summary": "List available models",
        "operationId": "listModels",
        "responses": {
          "200": {
            "description": "List of models",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ModelsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/pull": {
      "post": {
        "summary": "Pull a model",
        "operationId": "pullModel",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PullRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pull response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PullResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GenerateRequest": {
        "type": "object",
        "required": ["model", "prompt"],
        "properties": {
          "model": {
            "type": "string",
            "description": "Model name"
          },
          "prompt": {
            "type": "string",
            "description": "Input prompt"
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "options": {
            "$ref": "#/components/schemas/GenerationOptions"
          }
        }
      },
      "GenerateResponse": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string"
          },
          "response": {
            "type": "string"
          },
          "done": {
            "type": "boolean"
          },
          "context": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          }
        }
      },
      "ChatRequest": {
        "type": "object",
        "required": ["model", "messages"],
        "properties": {
          "model": {
            "type": "string"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "stream": {
            "type": "boolean",
            "default": false
          },
          "options": {
            "$ref": "#/components/schemas/GenerationOptions"
          }
        }
      },
      "ChatResponse": {
        "type": "object",
        "properties": {
          "model": {
            "type": "string"
          },
          "message": {
            "$ref": "#/components/schemas/Message"
          },
          "done": {
            "type": "boolean"
          }
        }
      },
      "Message": {
        "type": "object",
        "required": ["role", "content"],
        "properties": {
          "role": {
            "type": "string",
            "enum": ["system", "user", "assistant"]
          },
          "content": {
            "type": "string"
          }
        }
      },
      "ModelsResponse": {
        "type": "object",
        "properties": {
          "models": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Model"
            }
          }
        }
      },
      "Model": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "modified_at": {
            "type": "string",
            "format": "date-time"
          },
          "size": {
            "type": "integer"
          },
          "digest": {
            "type": "string"
          }
        }
      },
      "PullRequest": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": {
            "type": "string"
          },
          "insecure": {
            "type": "boolean",
            "default": false
          },
          "stream": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "PullResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string"
          },
          "digest": {
            "type": "string"
          },
          "total": {
            "type": "integer"
          },
          "completed": {
            "type": "integer"
          }
        }
      },
      "GenerationOptions": {
        "type": "object",
        "properties": {
          "num_keep": {
            "type": "integer"
          },
          "seed": {
            "type": "integer"
          },
          "num_predict": {
            "type": "integer"
          },
          "top_k": {
            "type": "integer"
          },
          "top_p": {
            "type": "number"
          },
          "temperature": {
            "type": "number"
          },
          "repeat_last_n": {
            "type": "integer"
          },
          "repeat_penalty": {
            "type": "number"
          },
          "presence_penalty": {
            "type": "number"
          },
          "frequency_penalty": {
            "type": "number"
          }
        }
      }
    }
  }
}