{
  "openapi": "3.1.0",
  "info": {
    "title": "The Best OKR System: agent API",
    "version": "1.0.0",
    "description": "Talk to Olle, the customer agent of The Best OKR System AB (Stockholm, Sweden): ask about the product and create an account. Free during early access."
  },
  "servers": [
    {
      "url": "https://thebestokrsystem.com"
    }
  ],
  "paths": {
    "/api/agent": {
      "get": {
        "summary": "How to talk to our agent",
        "operationId": "discover",
        "responses": {
          "200": {
            "description": "Steps, packages and limits"
          }
        }
      }
    },
    "/api/agent/sessions": {
      "post": {
        "summary": "Open a session (valid 24 hours)",
        "operationId": "createSession",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "agent_name": {
                    "type": "string",
                    "maxLength": 80
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Session created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NewSession"
                }
              }
            }
          },
          "429": {
            "description": "Too many sessions from your network"
          }
        }
      }
    },
    "/api/agent/sessions/{session_id}": {
      "get": {
        "summary": "Session status",
        "operationId": "getSession",
        "parameters": [
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ],
        "responses": {
          "200": {
            "description": "Status, messages left and sign-up result"
          },
          "404": {
            "description": "Unknown session"
          }
        }
      }
    },
    "/api/agent/sessions/{session_id}/messages": {
      "post": {
        "summary": "Send a message to our agent",
        "operationId": "sendMessage",
        "parameters": [
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "message"
                ],
                "properties": {
                  "message": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Our agent's reply",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Reply"
                }
              }
            }
          },
          "404": {
            "description": "Unknown session"
          },
          "410": {
            "description": "Session expired"
          },
          "413": {
            "description": "Message too long"
          },
          "429": {
            "description": "Message limit reached"
          }
        }
      },
      "get": {
        "summary": "The conversation so far",
        "operationId": "getMessages",
        "parameters": [
          {
            "$ref": "#/components/parameters/SessionId"
          }
        ],
        "responses": {
          "200": {
            "description": "All messages in this session"
          }
        }
      }
    },
    "/api/agent/start": {
      "get": {
        "summary": "GET-only: open a session (and optionally send the first message)",
        "operationId": "startSessionGet",
        "parameters": [
          {
            "name": "agent_name",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "message",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 2000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "session_id, optional reply, and next: ready-made GET links"
          }
        }
      }
    },
    "/api/agent/say": {
      "get": {
        "summary": "GET-only: send a message",
        "operationId": "sayGet",
        "parameters": [
          {
            "name": "session_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "message",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 2000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Our agent's reply, signup when an account was created, and next: ready-made GET links"
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "SessionId": {
        "name": "session_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "NewSession": {
        "type": "object",
        "properties": {
          "session_id": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "talk": {
            "type": "object",
            "description": "The next request to make"
          },
          "hint": {
            "type": "string"
          }
        }
      },
      "Reply": {
        "type": "object",
        "properties": {
          "session_id": {
            "type": "string"
          },
          "reply": {
            "type": "string",
            "description": "Our agent's answer"
          },
          "signup": {
            "type": [
              "object",
              "null"
            ],
            "description": "Set when this message created an account",
            "properties": {
              "company": {
                "type": "string"
              },
              "package": {
                "type": "string"
              },
              "username": {
                "type": "string"
              },
              "password": {
                "type": "string"
              },
              "login_url": {
                "type": "string"
              }
            }
          },
          "messages_left": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}