{
  "openapi": "3.1.0",
  "info": {
    "title": "AirCode Ø remote sessions",
    "version": "1.0.0",
    "description": "Personal project-scoped native sessions. Configure the issuing instance; this is separate from text-only Chat Completions."
  },
  "servers": [
    {
      "url": "https://your-instance.example/api/ai-gateway/v1"
    }
  ],
  "security": [
    {
      "gatewayToken": []
    }
  ],
  "paths": {
    "/session-catalog": {
      "get": {
        "summary": "Read the authorized project and live catalogue",
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Catalog"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions": {
      "get": {
        "summary": "Read up to 100 recent conversations owned by this token",
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "sessions": {
                      "type": "array",
                      "maxItems": 100,
                      "items": {
                        "$ref": "#/components/schemas/Session"
                      }
                    }
                  },
                  "required": [
                    "sessions"
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Start once per intention",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Launch"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}": {
      "get": {
        "summary": "Read the named conversation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Session"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/transcript": {
      "post": {
        "summary": "Read one named transcript page",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "offset": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0
                  },
                  "before": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Transcript"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/events": {
      "post": {
        "summary": "Live SSE transcript and state; reconnect from the last offset, never replay prompts",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "offset": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "minimum": 0
                  }
                },
                "required": []
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Keepalive comments, update events with {id,project,session,transcript}, or error events. Provider transcript cadence varies.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "description": "Access or reader-capacity refusal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/input": {
      "post": {
        "summary": "Send a follow-up once per intention",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "intention": {
                    "type": "string",
                    "pattern": "^[a-f0-9-]{36}$"
                  },
                  "text": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 65536,
                    "description": "Also limited to 64 KiB in UTF-8."
                  }
                },
                "required": [
                  "intention",
                  "text"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Acknowledgement"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/interaction": {
      "post": {
        "summary": "Answer the currently displayed dialog",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "intention": {
                    "type": "string",
                    "pattern": "^[a-f0-9-]{36}$"
                  },
                  "id": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "option": {
                    "type": "integer"
                  },
                  "options": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 16384
                  },
                  "dismiss": {
                    "type": "boolean"
                  },
                  "tab": {
                    "type": "integer"
                  }
                },
                "required": [
                  "intention",
                  "id"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Acknowledgement"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/command": {
      "post": {
        "summary": "Interrupt, close or select a catalogue-supported control",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "intention": {
                    "type": "string",
                    "pattern": "^[a-f0-9-]{36}$"
                  },
                  "action": {
                    "enum": [
                      "interrupt",
                      "close",
                      "model",
                      "effort",
                      "permission"
                    ]
                  },
                  "arg": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "intention",
                  "action"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Acknowledgement"
                }
              }
            }
          },
          "default": {
            "description": "Refused operation; an uncertain result must never be retried with a new intention.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/sessions/{id}/terminal": {
      "get": {
        "summary": "WebSocket terminal attachment; Authorization header required",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9-]{36}$"
            }
          },
          {
            "name": "X-Aircode-Terminal-Cols",
            "in": "header",
            "schema": {
              "type": "integer",
              "minimum": 20,
              "maximum": 500
            }
          },
          {
            "name": "X-Aircode-Terminal-Rows",
            "in": "header",
            "schema": {
              "type": "integer",
              "minimum": 5,
              "maximum": 200
            }
          }
        ],
        "description": "Raw output frames; client sends JSON {t:\"i\",d:string} or {t:\"r\",c:integer,r:integer}. Closing the socket detaches only.",
        "responses": {
          "101": {
            "description": "WebSocket upgrade"
          },
          "default": {
            "description": "Access refused"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "gatewayToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "acgw_ token with explicit project session scope"
      }
    },
    "schemas": {
      "Catalog": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "protocol": {
            "const": 1
          },
          "project": {
            "type": "string",
            "maxLength": 200
          },
          "streaming": {
            "const": "live"
          },
          "engines": {
            "type": "object",
            "additionalProperties": {
              "type": "object"
            }
          }
        },
        "required": [
          "protocol",
          "project",
          "engines",
          "streaming"
        ]
      },
      "Launch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "intention": {
            "type": "string",
            "pattern": "^[a-f0-9-]{36}$"
          },
          "engine": {
            "type": "string",
            "maxLength": 200
          },
          "model": {
            "type": "string",
            "maxLength": 200
          },
          "effort": {
            "type": "string",
            "maxLength": 200
          },
          "permissionMode": {
            "type": "string",
            "maxLength": 200
          },
          "name": {
            "type": "string",
            "maxLength": 80
          },
          "initialPrompt": {
            "type": "string",
            "minLength": 1,
            "maxLength": 65536,
            "description": "Also limited to 64 KiB in UTF-8."
          }
        },
        "required": [
          "intention",
          "engine",
          "model",
          "permissionMode",
          "initialPrompt"
        ]
      },
      "Session": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-f0-9-]{36}$"
          },
          "project": {
            "type": "string",
            "maxLength": 200
          },
          "session": {
            "type": "object",
            "required": [
              "tmuxName",
              "status",
              "engine"
            ],
            "properties": {
              "tmuxName": {
                "type": "string",
                "pattern": "^[a-f0-9-]{36}$"
              },
              "status": {
                "enum": [
                  "running",
                  "ended"
                ]
              },
              "engine": {
                "type": "string",
                "maxLength": 200
              }
            }
          }
        },
        "required": [
          "id",
          "project",
          "session"
        ]
      },
      "Transcript": {
        "type": "object",
        "required": [
          "events",
          "offset"
        ],
        "properties": {
          "events": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "offset": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "startOffset": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 0
          },
          "interaction": {
            "type": [
              "object",
              "null"
            ]
          },
          "terminalAttention": {
            "type": [
              "boolean",
              "object",
              "null"
            ]
          }
        }
      },
      "Acknowledgement": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "ok": {
            "const": true
          },
          "closed": {
            "type": "boolean"
          }
        },
        "required": [
          "ok"
        ]
      },
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "message",
              "code"
            ],
            "properties": {
              "message": {
                "type": "string"
              },
              "code": {
                "type": "string"
              }
            }
          }
        },
        "required": [
          "error"
        ]
      }
    }
  }
}
