{
  "openapi": "3.1.0",
  "info": {
    "title": "ReadMind agent API preview",
    "version": "1.0.0",
    "description": "Create a scoped personal access key in ReadMind at /agent-access. Keys expire after 90 days and can be revoked. This preview is a JSON API; OAuth and MCP are not available yet. Private notes, deletion and agent-driven imports are not exposed. Successful writes return a durable receipt. Read the connection guide at /for-agents."
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "AgentKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ReadMind personal access key"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "Author": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "Work": {
        "type": "object",
        "required": [
          "id",
          "title",
          "authors",
          "url"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "authors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Author"
            }
          },
          "url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "LibraryRecord": {
        "type": "object",
        "required": [
          "id",
          "book",
          "finished_on"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "book": {
            "$ref": "#/components/schemas/Work"
          },
          "finished_on": {
            "type": [
              "string",
              "null"
            ],
            "format": "date"
          }
        }
      },
      "LibraryPage": {
        "type": "object",
        "required": [
          "kind",
          "data",
          "next_after_id"
        ],
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "readings",
              "ownership"
            ]
          },
          "data": {
            "type": "array",
            "maxItems": 50,
            "items": {
              "$ref": "#/components/schemas/LibraryRecord"
            }
          },
          "next_after_id": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "CataloguePage": {
        "type": "object",
        "required": [
          "data",
          "truncated",
          "match_policy"
        ],
        "properties": {
          "data": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "$ref": "#/components/schemas/Work"
            }
          },
          "truncated": {
            "type": "boolean"
          },
          "match_policy": {
            "type": "string"
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "operation_id",
          "action",
          "outcome",
          "book",
          "record",
          "completed_at"
        ],
        "properties": {
          "operation_id": {
            "type": "string",
            "format": "uuid"
          },
          "action": {
            "type": "string",
            "enum": [
              "mark_read",
              "record_reading",
              "mark_owned",
              "add_copy"
            ]
          },
          "outcome": {
            "type": "string",
            "enum": [
              "created",
              "already_present"
            ]
          },
          "book": {
            "$ref": "#/components/schemas/Work"
          },
          "record": {
            "type": "object",
            "required": [
              "id",
              "kind",
              "finished_on"
            ],
            "properties": {
              "id": {
                "type": "integer"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "reading",
                  "ownership"
                ]
              },
              "finished_on": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date"
              }
            }
          },
          "completed_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkResponse": {
        "type": "object",
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "$ref": "#/components/schemas/Work"
          }
        }
      }
    }
  },
  "paths": {
    "/books": {
      "get": {
        "summary": "Find local candidate works by q and optional author, or ISBN. Unknown ISBNs never fall back to title guesses. At most 20 candidates; resolve ambiguity explicitly.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "catalogue:read",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CataloguePage"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Title search, 2\u2013200 characters.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "author",
            "in": "query",
            "description": "Optional author filter for title searches.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "isbn",
            "in": "query",
            "description": "ISBN-10 or ISBN-13. Takes precedence over title queries.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "operationId": "searchBooks"
      }
    },
    "/books/{id}": {
      "get": {
        "summary": "Get a work, resolving retired IDs.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "catalogue:read",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WorkResponse"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid",
              "description": "A canonical or retired ReadMind work ID. Resolve a book explicitly before writing."
            }
          }
        ],
        "operationId": "getBook"
      }
    },
    "/library": {
      "get": {
        "summary": "List this account's reading records or owned copies, excluding private notes. Returns 50 records and next_after_id.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "library:read",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LibraryPage"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "readings",
                "ownership"
              ],
              "default": "readings"
            }
          },
          {
            "name": "after_id",
            "in": "query",
            "description": "Nonnegative integer cursor returned by the previous response.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "operationId": "getMyLibrary"
      }
    },
    "/readings": {
      "post": {
        "summary": "Record a completed book or an intentional reread.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "reading:write",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Keep the same key on retries of the same action. Use a new key for a distinct action.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "book_id"
                ],
                "properties": {
                  "book_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "A canonical or retired ReadMind work ID. Resolve a book explicitly before writing."
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "ensure",
                      "another"
                    ],
                    "default": "ensure",
                    "description": "ensure preserves existing records. another explicitly adds a reread or additional copy; retries still use the same idempotency key."
                  },
                  "finished_on": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date",
                    "description": "Known completion calendar date, YYYY-MM-DD. Omit if unknown. ensure never overwrites an existing reading."
                  }
                }
              }
            }
          }
        },
        "operationId": "recordReading"
      }
    },
    "/ownership": {
      "post": {
        "summary": "Record ownership or an intentional additional copy.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "ownership:write",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "description": "Keep the same key on retries of the same action. Use a new key for a distinct action.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9._:-]{1,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "book_id"
                ],
                "properties": {
                  "book_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "A canonical or retired ReadMind work ID. Resolve a book explicitly before writing."
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "ensure",
                      "another"
                    ],
                    "default": "ensure",
                    "description": "ensure preserves existing records. another explicitly adds a reread or additional copy; retries still use the same idempotency key."
                  }
                }
              }
            }
          }
        },
        "operationId": "recordOwnership"
      }
    },
    "/operations/{id}": {
      "get": {
        "summary": "Retrieve a receipt created by this connection.",
        "security": [
          {
            "AgentKey": []
          }
        ],
        "x-required-permission": "Any active permission on the original connection",
        "responses": {
          "200": {
            "description": "Successful result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "401": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Request could not be completed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "operationId": "getOperation"
      }
    }
  }
}
