{"openapi":"3.1.0","info":{"title":"Headknot API","description":"Search and ask your Headknot workspaces. Every answer carries the sources it is drawn from. Authenticate with an API key from Settings as `Authorization: Bearer hk_…`.","version":"v1"},"externalDocs":{"description":"Project Docs","url":"https://example.com/docs"},"servers":[{"url":"https://api.headknot.com/api","description":"Generated server url"}],"security":[{"bearer":[]}],"tags":[{"name":"Documents","description":"Read a workspace's documents and add to them"},{"name":"Account","description":"The credential, its account and its workspaces"},{"name":"Ask","description":"Search a workspace and ask it questions"}],"paths":{"/v1/workspaces/{workspaceId}/search":{"post":{"tags":["Ask"],"summary":"Find the passages that answer a query","description":"Semantic Search: the quoted passages and their sources, best first. Free on every plan. Needs the `read` scope. `workspaceId` comes from GET /v1/workspaces.","operationId":"search","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1SearchRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1Answer"}}}}}}},"/v1/workspaces/{workspaceId}/files":{"post":{"tags":["Documents"],"summary":"Upload files","description":"One or more files in the `files` form field, or a .zip (expanded), with the app's limits (10 MB a file). Read in the background; the words count against your plan exactly as an upload in the app does. Needs the `write` scope.","operationId":"upload","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"multipart/form-data":{"schema":{"type":"object","properties":{"files":{"type":"array","items":{"type":"string","format":"binary"}}},"required":["files"]}}}},"responses":{"202":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1UploadResult"}}}}}}},"/v1/workspaces/{workspaceId}/documents":{"get":{"tags":["Documents"],"summary":"List the workspace's documents","description":"Newest first. Only documents whose source you may view are listed. Needs the `read` scope.","operationId":"list","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"limit","in":"query","description":"1 to 100, default 50","required":false,"schema":{"type":"integer","format":"int32"}},{"name":"offset","in":"query","description":"From a previous page's `nextOffset`","required":false,"schema":{"type":"integer","format":"int32","default":0}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1DocumentPage"}}}}}},"post":{"tags":["Documents"],"summary":"Add a note","description":"Stored and searched like an uploaded file named after its title. Read in the background; the words count against your plan as an upload does. Needs the `write` scope.","operationId":"addNote","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1NoteRequest"}}},"required":true},"responses":{"202":{"description":"Accepted","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1UploadResult"}}}}}}},"/v1/workspaces/{workspaceId}/ask":{"post":{"tags":["Ask"],"summary":"Ask a question","description":"A cited answer from the workspace's sources. In `reasoning` mode (the default) it counts against your AI Reasoning allowance, exactly as in the app, and answers 402 when that is used up; a declined answer is not counted. `search` mode is free. Needs the `ask` scope.","operationId":"ask","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1AskRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1Answer"}}}}}}},"/v1/workspaces/{workspaceId}/ask/stream":{"post":{"tags":["Ask"],"summary":"Ask a question, streamed","description":"Server-Sent Events: `token` events carry the answer as it is written ({\"text\": …}), then one `answer` event carries the whole Answer, then the stream closes. A failure is an `error` event ({\"code\", \"message\"}). Access and the allowance are checked before the stream opens, so those refusals are ordinary 403 / 402 responses. Needs the `ask` scope.","operationId":"askStream","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1AskRequest"}}},"required":true},"responses":{"200":{"description":"OK","content":{"text/event-stream":{"schema":{"$ref":"#/components/schemas/SseEmitter"}},"application/json":{"schema":{"$ref":"#/components/schemas/SseEmitter"}}}}}}},"/v1/workspaces":{"get":{"tags":["Account"],"summary":"List the workspaces this credential can use","description":"Active workspaces you own or are a member of, narrowed to the credential's workspace list. Needs the `read` scope.","operationId":"workspaces","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/V1Workspace"}}}}}}}},"/v1/workspaces/{workspaceId}/documents/{documentId}":{"get":{"tags":["Documents"],"summary":"Read a document","description":"Its current text, as extracted from the source. `documentId` is a citation's `documentId` or an `id` from the list. 404 when it is not in the workspace, was excluded, or its source is not one you may view. Needs the `read` scope.","operationId":"read","parameters":[{"name":"workspaceId","in":"path","description":"A workspace from GET /v1/workspaces","required":true,"schema":{"type":"string","format":"uuid"}},{"name":"documentId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],"responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1DocumentContent"}}}}}}},"/v1/me":{"get":{"tags":["Account"],"summary":"Who this credential acts as","description":"The account, its plan, its AI Reasoning answers this period, and what the credential may do. Needs no scope.","operationId":"me","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/V1Me"}}}}}}}},"components":{"schemas":{"V1SearchRequest":{"type":"object","description":"Find the passages in a workspace that answer a query.","properties":{"query":{"type":"string","description":"What to look for, in plain language.","example":"Q3 pricing decision","maxLength":4000,"minLength":0}},"required":["query"]},"V1Answer":{"type":"object","description":"An answer with the sources it is drawn from. Quote it with its citations: every claim in it traces to one.","properties":{"answer":{"type":"string","description":"The answer; [n] markers refer to `citations`."},"mode":{"type":"string","enum":["reasoning","search"]},"abstained":{"type":"boolean","description":"True when the workspace does not hold enough to answer. A declined AI Reasoning answer is not counted against the allowance."},"citations":{"type":"array","items":{"$ref":"#/components/schemas/V1Citation"}},"passages":{"type":"array","description":"Matching passages, quoted (search mode).","items":{"$ref":"#/components/schemas/V1Passage"}},"conversationId":{"type":"string","format":"uuid","description":"Pass it back as `conversationId` to ask a follow-up."},"turnId":{"type":"string","format":"uuid"}}},"V1Citation":{"type":"object","description":"A source an answer is drawn from.","properties":{"index":{"type":"integer","format":"int32","description":"1-based; an answer's [n] markers refer to it."},"title":{"type":"string"},"sourceApp":{"type":"string","description":"Where it came from, e.g. NOTION, SLACK, FILE_UPLOAD."},"url":{"type":"string","description":"A link to the original, when the source has one."},"documentId":{"type":"string","format":"uuid","description":"The document's id in Headknot."},"quote":{"type":"string","description":"The words the answer relies on."},"excerpt":{"type":"string","description":"A short extract of the document."},"author":{"type":"string"},"noteId":{"type":"string","format":"uuid","description":"The Notebook note this cites, when it cites a note sentence rather than a document; fetch it as note:<noteId>."},"spanKey":{"type":"string","description":"The cited sentence's key in that note."}}},"V1Passage":{"type":"object","description":"A quoted passage that matches the question.","properties":{"quote":{"type":"string"},"citation":{"type":"integer","format":"int32","description":"The `index` of the citation it is quoted from."}}},"V1UploadAdded":{"type":"object","properties":{"fileId":{"type":"string","format":"uuid"},"filename":{"type":"string"},"sizeBytes":{"type":"integer","format":"int64"},"version":{"type":"integer","format":"int32"}}},"V1UploadResult":{"type":"object","description":"What was accepted. Accepted files are processed in the background and appear in the document list once read; the words are counted against your plan exactly as an upload in the app is.","properties":{"added":{"type":"array","items":{"$ref":"#/components/schemas/V1UploadAdded"}},"skipped":{"type":"array","items":{"$ref":"#/components/schemas/V1UploadSkipped"}}}},"V1UploadSkipped":{"type":"object","properties":{"filename":{"type":"string"},"reason":{"type":"string"}}},"V1NoteRequest":{"type":"object","description":"A note to add to the workspace, stored and searched like an uploaded file.","properties":{"title":{"type":"string","example":"Decision: Q3 pricing","maxLength":200,"minLength":0},"text":{"type":"string","maxLength":1000000,"minLength":0},"format":{"type":"string","description":"`markdown` (default) or `text`.","enum":["markdown","text"],"pattern":"(?i)markdown|text"}},"required":["text","title"]},"V1AskRequest":{"type":"object","description":"A question about a workspace's sources.","properties":{"question":{"type":"string","description":"The question, in plain language.","example":"What did we decide about the Q3 pricing change?","maxLength":4000,"minLength":0},"mode":{"type":"string","description":"`reasoning` (default): a written answer, counted against your AI Reasoning allowance. `search`: the passages that answer it, free.","enum":["reasoning","search"],"pattern":"(?i)reasoning|search"},"conversationId":{"type":"string","format":"uuid","description":"Continue a conversation: the `conversationId` of an earlier answer. Omit to start a new one."}},"required":["question"]},"SseEmitter":{"type":"object","properties":{"timeout":{"type":"integer","format":"int64"}}},"V1Workspace":{"type":"object","properties":{"id":{"type":"string","format":"uuid"},"name":{"type":"string"},"slug":{"type":"string"},"personal":{"type":"boolean","description":"Your own personal workspace."}}},"V1Document":{"type":"object","description":"A document the workspace holds.","properties":{"id":{"type":"string","format":"uuid","description":"The same id a citation's `documentId` carries."},"title":{"type":"string"},"sourceApp":{"type":"string","description":"Where it came from, e.g. NOTION, SLACK, FILE_UPLOAD."},"url":{"type":"string","description":"A link to the original, when the source has one."},"updatedAt":{"type":"string","format":"date-time","description":"When its current content was captured."}}},"V1DocumentPage":{"type":"object","properties":{"documents":{"type":"array","items":{"$ref":"#/components/schemas/V1Document"}},"nextOffset":{"type":"integer","format":"int32","description":"Pass as `offset` for the next page; null when there is none. A page can hold fewer than `limit` documents."}}},"V1DocumentContent":{"type":"object","description":"A document and its current text.","properties":{"id":{"type":"string","format":"uuid"},"title":{"type":"string"},"sourceApp":{"type":"string"},"url":{"type":"string"},"updatedAt":{"type":"string","format":"date-time"},"text":{"type":"string","description":"The text, exactly as it was extracted from the source."}}},"V1AiReasoning":{"type":"object","description":"AI Reasoning answers this period. Search is free and not counted.","properties":{"used":{"type":"integer","format":"int64"},"limit":{"type":"integer","format":"int64","description":"Null when unlimited."},"remaining":{"type":"integer","format":"int64","description":"Null when unlimited."}}},"V1Credential":{"type":"object","properties":{"type":{"type":"string","enum":["api_key","oauth"]},"scopes":{"type":"array","description":"read, ask, write","items":{"type":"string"}},"workspaceIds":{"type":"array","description":"Workspaces it is limited to; empty for all of yours.","items":{"type":"string","format":"uuid"}}}},"V1Me":{"type":"object","description":"Who this credential acts as, and what it may do.","properties":{"userId":{"type":"string","format":"uuid"},"email":{"type":"string"},"plan":{"$ref":"#/components/schemas/V1Plan"},"aiReasoning":{"$ref":"#/components/schemas/V1AiReasoning"},"credential":{"$ref":"#/components/schemas/V1Credential"}}},"V1Plan":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"}}}},"securitySchemes":{"bearer":{"type":"http","description":"An API key (hk_live_…) or an access token","scheme":"bearer"}}}}