{
  "openapi": "3.1.0",
  "info": {
    "title": "Kylon Tools API",
    "description": "Kylon Tools API for discovering, authorizing, inspecting, executing, proxying, and staging files for connected tools. Connection operations require an agent identity; connections remain limited to those linked to that agent.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.kylon.io",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKey": []
    },
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/proxy/tools/connections": {
      "get": {
        "operationId": "listConnections",
        "summary": "List connections",
        "description": "List all connections currently linked to your agent.",
        "tags": [
          "Connections"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connections": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Connection"
                      }
                    }
                  },
                  "required": [
                    "connections"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/proxy/tools/search": {
      "get": {
        "operationId": "searchToolkits",
        "summary": "Search toolkits",
        "description": "Search available toolkits by keywords. Returns both native and third-party integrations.",
        "tags": [
          "Toolkits"
        ],
        "parameters": [
          {
            "name": "keywords",
            "in": "query",
            "required": true,
            "description": "Search keywords matched against toolkit slug, name, and description.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Positive result limit, default 50. Values above 100 are capped at 100.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Pagination cursor from a previous response.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "toolkits": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ToolkitSummary"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Cursor for the next page of results."
                    },
                    "nextStep": {
                      "type": "string",
                      "description": "Recommended next step after toolkit discovery."
                    }
                  },
                  "required": [
                    "toolkits",
                    "nextCursor",
                    "nextStep"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/proxy/tools/auth": {
      "post": {
        "operationId": "getAuthUrl",
        "summary": "Get auth URL",
        "description": "Start connection authorization and return a user-facing URL plus instructions. Inbound messaging endpoints such as LINE require the in-product setup form instead (messaging_setup_requires_ui).",
        "tags": [
          "Connections"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "toolkit": {
                    "type": "string",
                    "description": "Toolkit slug (from search results)."
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Optional provider-specific OAuth scopes."
                  },
                  "redirect_url": {
                    "type": "string",
                    "description": "Agent-started proxy authorization uses Kylon's connection popup callback; this field does not override it."
                  },
                  "connection_intent": {
                    "$ref": "#/components/schemas/ConnectionUseIntent"
                  }
                },
                "required": [
                  "toolkit"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "redirectUrl": {
                      "type": "string",
                      "description": "URL to open in a browser to complete the OAuth flow."
                    },
                    "agentInstruction": {
                      "type": "string",
                      "description": "Instructions for presenting the authorization link."
                    }
                  },
                  "required": [
                    "redirectUrl",
                    "agentInstruction"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/proxy/tools/toolkit/{toolkit}": {
      "get": {
        "operationId": "getToolkitDetails",
        "summary": "Get toolkit details",
        "description": "Get toolkit metadata and a page of tools with input schemas. Use nextCursor to continue. Some native toolkits intentionally have no structured tools; read note for the supported HTTP or CLI surface.",
        "tags": [
          "Toolkits"
        ],
        "parameters": [
          {
            "name": "toolkit",
            "in": "path",
            "required": true,
            "description": "Toolkit slug.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Positive result limit, default 50. Values above 100 are capped at 100.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Pagination cursor.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "connection_id",
            "in": "query",
            "required": false,
            "description": "Linked connection to inspect. Required for MCP toolkits, whose tools are server-defined.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ToolkitDetails"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/proxy/tools/toolkit/{toolkit}/search": {
      "get": {
        "operationId": "searchToolkitTools",
        "summary": "Search toolkit tools",
        "description": "Search tools within a specific toolkit by query string.",
        "tags": [
          "Toolkits"
        ],
        "parameters": [
          {
            "name": "toolkit",
            "in": "path",
            "required": true,
            "description": "Toolkit slug.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search query to filter tools.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Positive result limit, default 50. Values above 100 are capped at 100.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Pagination cursor.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "connection_id",
            "in": "query",
            "required": false,
            "description": "Linked connection to inspect. Required for MCP toolkits, whose tools are server-defined.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tools": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Tool"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "toolkit": {
                      "$ref": "#/components/schemas/ToolkitSummary"
                    },
                    "note": {
                      "type": "string",
                      "description": "Explains an intentionally empty structured tool list and usable alternative surfaces."
                    },
                    "api_key_connections": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiKeyConnectionMatch"
                      },
                      "description": "Optional first-page matches among the calling agent's API-key connections."
                    }
                  },
                  "required": [
                    "tools",
                    "toolkit",
                    "nextCursor"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        }
      }
    },
    "/proxy/tools/execute": {
      "post": {
        "operationId": "executeTool",
        "summary": "Execute tool",
        "description": "Execute the exact tool slug with schema-shaped arguments. Returns a connection envelope, not bare provider data. Raw calls do not post Draft or Email cards in chat.",
        "tags": [
          "Execution"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tool": {
                    "type": "string",
                    "description": "Tool slug (from toolkit details)."
                  },
                  "arguments": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Tool-specific arguments."
                  },
                  "connection_id": {
                    "type": "string",
                    "description": "Specific linked connection; required for MCP tools and when selection is ambiguous."
                  }
                },
                "required": [
                  "tool"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExecutionResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "description": "Connected provider rate limit or script usage limit. Inspect error and guidance before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ExecutionResult"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Workspace credits unavailable or credit capability not covered.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Workspace state or connection access refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/proxy/tools/proxy": {
      "post": {
        "operationId": "proxyRequest",
        "summary": "Proxy request",
        "description": "Make an authenticated HTTP request through a native toolkit's API. The system injects the connection's credentials automatically.",
        "tags": [
          "Execution"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "toolkit": {
                    "type": "string",
                    "description": "Toolkit slug."
                  },
                  "method": {
                    "type": "string",
                    "description": "HTTP method."
                  },
                  "url": {
                    "type": "string",
                    "description": "Full URL on the native toolkit's allowed origin. For custom API-key connections it must match the configured HTTPS base URL origin."
                  },
                  "headers": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    },
                    "description": "Additional HTTP headers."
                  },
                  "body": {
                    "description": "Request body (for POST/PUT/PATCH)."
                  },
                  "connection_id": {
                    "type": "string",
                    "description": "Specific linked native connection. Required when more than one matches the toolkit."
                  }
                },
                "required": [
                  "toolkit",
                  "method",
                  "url"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExecutionResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "429": {
            "description": "Connected provider rate limit or script usage limit. Inspect error and guidance before retrying.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/ExecutionResult"
                    },
                    {
                      "$ref": "#/components/schemas/Error"
                    }
                  ]
                }
              }
            }
          },
          "402": {
            "description": "Workspace credits unavailable or credit capability not covered.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Workspace state or connection access refused.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/proxy/tools/upload": {
      "post": {
        "operationId": "uploadFile",
        "summary": "Upload file",
        "description": "Stage a multipart file up to 500 MiB (524,288,000 bytes) for supported connection tools or OpenRouter video reference assets. Returns stagingKey, filename, contentType, and byte size.",
        "tags": [
          "Execution"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The file to upload."
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "413": {
            "description": "File too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Kylon agent API credential. A workspace service key lacks the agent identity required by connection operations."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Use a Kylon agent API credential. Keep runtime-provided signed context attached to the token."
      }
    },
    "schemas": {
      "Connection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Connection ID. Use as `connection_id` in other endpoints."
          },
          "toolkit": {
            "type": "string",
            "description": "Toolkit slug; use the returned slug rather than deriving it from a display name."
          },
          "remoteUser": {
            "type": [
              "string",
              "null"
            ],
            "description": "Remote user identifier (e.g. @handle, email)."
          },
          "label": {
            "type": [
              "string",
              "null"
            ],
            "description": "Human-readable label."
          },
          "createdAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "toolkit",
          "remoteUser",
          "label",
          "createdAt"
        ]
      },
      "ToolkitSummary": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "description": "Toolkit identifier used in all endpoints."
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "icon": {
            "type": [
              "string",
              "null"
            ],
            "description": "URL to the toolkit icon."
          }
        },
        "required": [
          "slug",
          "name",
          "description",
          "icon"
        ]
      },
      "ToolkitDetails": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "icon": {
            "type": [
              "string",
              "null"
            ]
          },
          "tools": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tool"
            }
          },
          "nextCursor": {
            "type": [
              "string",
              "null"
            ]
          },
          "note": {
            "type": "string",
            "description": "Explains an intentionally empty structured tool list and usable alternative surfaces."
          }
        },
        "required": [
          "slug",
          "name",
          "description",
          "tools",
          "icon",
          "nextCursor"
        ]
      },
      "Tool": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "description": "Tool identifier used in the execute endpoint."
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "inputParameters": {
            "description": "JSON Schema describing the expected arguments. Null for tools with dynamic schemas.",
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": true
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "slug",
          "name",
          "description",
          "inputParameters"
        ]
      },
      "ExecutionResult": {
        "type": "object",
        "properties": {
          "data": {
            "description": "Tool execution result data."
          },
          "error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Error message if execution failed."
          },
          "successful": {
            "type": "boolean"
          },
          "statusCode": {
            "type": "integer",
            "description": "HTTP status of the tool result."
          },
          "connectionId": {
            "type": [
              "string",
              "null"
            ],
            "description": "Selected connection, when known."
          },
          "providerRequestId": {
            "type": [
              "string",
              "null"
            ]
          },
          "hint": {
            "type": [
              "string",
              "null"
            ],
            "description": "Recovery hint, when present."
          },
          "structuredContent": {
            "description": "Structured MCP result, when supplied."
          },
          "rateLimited": {
            "type": "boolean"
          },
          "retryable": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          },
          "presentation": {
            "type": "object",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "connection_draft_card",
                  "email_card"
                ]
              },
              "state": {
                "const": "not_presented"
              },
              "visibleMessageReady": {
                "const": false
              },
              "agentInstruction": {
                "type": "string"
              }
            },
            "required": [
              "kind",
              "state",
              "visibleMessageReady",
              "agentInstruction"
            ],
            "description": "Raw proxy calls do not post chat cards. Use the card-aware built-in tool or CLI for interactive presentation."
          }
        },
        "required": [
          "data",
          "error",
          "successful",
          "statusCode"
        ]
      },
      "UploadResult": {
        "type": "object",
        "properties": {
          "stagingKey": {
            "type": "string",
            "description": "Workspace-scoped staging reference. Pass it in the selected tool schema field, or the nested url field for OpenRouter video references; it is not a public URL."
          },
          "contentType": {
            "type": "string"
          },
          "size": {
            "type": "integer",
            "description": "File size in bytes."
          },
          "filename": {
            "type": "string"
          }
        },
        "required": [
          "stagingKey",
          "contentType",
          "size",
          "filename"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "code": {
            "oneOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          },
          "guidance": {
            "description": "Instructions for recovering from a script policy refusal."
          },
          "recoverable": {
            "type": "boolean"
          },
          "suggested_connections": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        },
        "required": [
          "error"
        ]
      },
      "ConnectionUseIntent": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "one_off_access",
              "realtime_delivery",
              "scheduled_digest",
              "context_discovery",
              "unknown"
            ]
          },
          "task_summary": {
            "type": "string",
            "maxLength": 500
          },
          "cadence": {
            "type": "string",
            "maxLength": 120,
            "description": "Required and non-empty for scheduled_digest."
          }
        },
        "required": [
          "kind"
        ],
        "description": "Why authorization is requested. Missing or malformed intent normalizes to unknown; scheduled_digest without cadence is rejected."
      },
      "ApiKeyConnectionMatch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "service_name": {
            "type": "string"
          },
          "label": {
            "type": [
              "string",
              "null"
            ]
          },
          "configured_env_vars": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "status": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "service_name",
          "label",
          "configured_env_vars",
          "status"
        ]
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Bad request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Unauthorized - invalid or missing API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
