| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731 |
- {
- "openapi": "3.1.0",
- "info": {
- "title": "smartbotic-vectorapi",
- "version": "0.8.0",
- "description": "General-purpose REST API fronting smartbotic-database. Supports multi-project namespacing and multi-key authorization with per-project grants."
- },
- "components": {
- "securitySchemes": {
- "bearerAuth": {
- "type": "http",
- "scheme": "bearer",
- "description": "API key issued by the /api/v1/keys endpoint. Pass as Authorization: Bearer <KEY>."
- }
- },
- "pathItems": {
- "FunctionDispatch": {
- "get": {
- "tags": [
- "Functions"
- ],
- "summary": "Invoke a published function",
- "description": "Served without authentication. The function's returned status, headers and body are sent as-is; an object carrying none of those keys is sent as a 200 body. Cookie, Authorization, Proxy-Authorization and X-Captcha-Token are not forwarded to the function, because the web UI shares this origin and forwarding Cookie would hand an admin session to every function author in the project. Repeated query parameters collapse to the last value, and HEAD is not routable.",
- "security": [],
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project owning the function. Must exist; charset is restricted to [A-Za-z0-9_-]."
- },
- {
- "name": "path",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The remainder of the path, matched against the project's declared routes. A '..' segment is refused."
- }
- ],
- "responses": {
- "200": {
- "description": "Whatever the function returned. The status, headers and content type are the function's own.",
- "content": {
- "application/json": {
- "schema": {}
- }
- }
- },
- "404": {
- "description": "No enabled, valid function matches this path. Disabled and invalid functions are absent from matching, so a public caller cannot tell them from a path that was never published.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "405": {
- "description": "The path matches a function that does not declare this method. Carries an Allow header listing the methods every function on this path declares.",
- "headers": {
- "Allow": {
- "schema": {
- "type": "string"
- },
- "description": "e.g. \"GET, PUT\""
- }
- },
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "500": {
- "description": "The function threw (code function_error), or exceeded its memory ceiling (function_out_of_memory). The function's error text is deliberately NOT included - a stack trace on an open endpoint is an information leak. error.details.run_id locates the full message in the function's run log.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "503": {
- "description": "No healthy runner (code runner_unavailable). Transient; carries Retry-After.",
- "headers": {
- "Retry-After": {
- "schema": {
- "type": "string"
- }
- }
- },
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "504": {
- "description": "The function exceeded its wall-time budget (code function_timeout).",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- }
- }
- },
- "schemas": {
- "FunctionDescriptor": {
- "type": "object",
- "description": "The `on` block a function exports. Unknown keys are ignored so a script written for a later server still loads, and a parse failure is data rather than an exception.",
- "properties": {
- "id": {
- "type": "string",
- "description": "The function's identity, declared in the source. The file path is incidental, so a rename carries the policy with it."
- },
- "type": {
- "type": "string",
- "enum": [
- "http",
- "cron",
- "db",
- "job"
- ],
- "description": "What starts a run. `http` serves a route under /fn/{project}/. `cron` fires on a schedule. `db` fires on an INSERT/UPDATE/DELETE in a watched collection. `job` is reached only by being enqueued, which is where slow work belongs."
- },
- "route": {
- "type": "string",
- "description": "HTTP trigger: the path pattern, with `:name` segments captured into ctx.params"
- },
- "method": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "HTTP trigger: accepted methods, upper-cased. ABSENT means every method, not none."
- },
- "schedule": {
- "type": "string",
- "description": "Five-field cron expression, required for `type: cron`. With `tz`, an IANA zone validated against the host's time-zone database at PUSH time - an unknown zone is refused, never silently UTC."
- },
- "table": {
- "type": "string",
- "description": "Watched collection, required for `type: db`."
- },
- "event": {
- "type": "string",
- "enum": [
- "INSERT",
- "UPDATE",
- "DELETE"
- ],
- "description": "Required for `type: db`."
- },
- "timeoutMs": {
- "type": "integer",
- "description": "Declared wall-clock budget. Omitted when the script did not declare one; a declared value is still clamped to the runner's configured maximum."
- },
- "singleFlight": {
- "type": "boolean",
- "description": "Skip a tick while the previous run is still going. Defaults to TRUE for cron and false otherwise."
- },
- "tz": {
- "type": "string",
- "description": "IANA zone for a cron schedule, validated at push time."
- }
- },
- "required": [
- "id",
- "type"
- ]
- },
- "FunctionPolicy": {
- "type": "object",
- "description": "What a function may touch, in exactly the vocabulary API keys use - a function is a principal, not a key holder. Policy is SERVER state: it is set only by an admin through PUT .../functions/{id}/policy, and a `policy` field sent with a code push is ignored. An empty or absent rule set grants no collection at all, which is what a first registration inherits.",
- "properties": {
- "rules": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/KeyScopeRule"
- },
- "description": "A function reaches a collection only if a matching rule exists for the (collection, op) pair. Unlike a key scope, an empty array is legal: it is the deny-everything default."
- },
- "origins": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "Unused for functions; carried because the policy shares the key-scope shape"
- },
- "rate_limit_per_min": {
- "type": "integer",
- "minimum": 0,
- "description": "Maximum runs per minute. 0 means unlimited."
- },
- "expires_at": {
- "type": "integer",
- "description": "Unix epoch seconds after which the policy is treated as expired. 0 means never."
- }
- }
- },
- "FunctionSummary": {
- "type": "object",
- "description": "A registry row without its source. Listings return this shape so one response does not ship every function's whole body.",
- "properties": {
- "function_id": {
- "type": "string",
- "description": "Declared in the script's `on` block. Called `function_id`, not `id`, because the database client strips a top-level `id` from stored bodies."
- },
- "path": {
- "type": "string",
- "description": "Where the author keeps the file. Carries no meaning: changing it keeps the same row, and the policy with it."
- },
- "content_hash": {
- "type": "string",
- "description": "sha256 of the source, lower-case hex. The runner caches compiled bytecode by this."
- },
- "descriptor": {
- "$ref": "#/components/schemas/FunctionDescriptor"
- },
- "policy": {
- "$ref": "#/components/schemas/FunctionPolicy"
- },
- "enabled": {
- "type": "boolean",
- "description": "Server state: re-pushing code never re-enables a function an operator turned off"
- },
- "valid": {
- "type": "boolean"
- },
- "last_error": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- },
- "updated_at": {
- "type": "integer"
- }
- },
- "required": [
- "function_id",
- "descriptor",
- "policy",
- "enabled",
- "valid"
- ]
- },
- "Function": {
- "allOf": [
- {
- "$ref": "#/components/schemas/FunctionSummary"
- },
- {
- "type": "object",
- "properties": {
- "source": {
- "type": "string",
- "description": "The JavaScript as stored. Returned by the single-function GET only."
- }
- }
- }
- ]
- },
- "RunnerStatus": {
- "type": "object",
- "description": "Runner reachability, carried by the functions listing so a client can warn that a write will fail before an author writes a script.",
- "properties": {
- "configured": {
- "type": "integer",
- "description": "Endpoints in the server's functions.runners list. 0 means functions cannot be stored at all - installing the runner package does not switch them on."
- },
- "healthy": {
- "type": "integer",
- "description": "How many answered their last health check."
- }
- }
- },
- "FunctionRun": {
- "type": "object",
- "description": "One recorded run. The log is append-only and trimmed to the newest N runs per function on every write, so an old run_id eventually stops resolving.",
- "properties": {
- "run_id": {
- "type": "string"
- },
- "function_id": {
- "type": "string"
- },
- "trigger": {
- "type": "string",
- "enum": [
- "http",
- "invoke"
- ],
- "description": "`http` for a dispatched request, `invoke` for a manual POST .../invoke"
- },
- "ok": {
- "type": "boolean"
- },
- "status": {
- "type": "integer"
- },
- "duration_ms": {
- "type": "integer"
- },
- "error": {
- "type": "string"
- },
- "console": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "started_at": {
- "type": "integer",
- "description": "Unix epoch seconds"
- }
- }
- },
- "FunctionRunResult": {
- "type": "object",
- "description": "What one run produced. The HTTP status of the invoke call reports whether the run could be PERFORMED; this envelope reports what the function did.",
- "properties": {
- "run_id": {
- "type": "string",
- "description": "Also the id of the run-log entry this invoke appended"
- },
- "ok": {
- "type": "boolean"
- },
- "status": {
- "type": "integer",
- "description": "The status the function returned"
- },
- "headers": {
- "type": "object",
- "additionalProperties": {
- "type": "string"
- }
- },
- "body": {
- "description": "Whatever the function returned; any JSON type, including null"
- },
- "console": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "duration_ms": {
- "type": "integer"
- },
- "error": {
- "type": "string"
- },
- "timed_out": {
- "type": "boolean"
- },
- "out_of_memory": {
- "type": "boolean"
- }
- }
- },
- "ProjectSecret": {
- "type": "object",
- "description": "One per-project function secret, as the API reports it. The value is write-only and never appears here, not masked and not as a length.",
- "properties": {
- "name": {
- "type": "string",
- "pattern": "^[A-Z_][A-Z0-9_]*$",
- "maxLength": 64
- },
- "set": {
- "type": "boolean",
- "description": "Whether a value is stored"
- },
- "created_at": {
- "type": "integer",
- "description": "Unix seconds of the first write"
- },
- "updated_at": {
- "type": "integer",
- "description": "Unix seconds of the last rotation"
- }
- },
- "required": [
- "name",
- "set"
- ]
- },
- "ProjectEmbeddingSettings": {
- "type": "object",
- "description": "Three views of a project's embedding configuration. In overrides, an empty string means the field is inherited.",
- "properties": {
- "effective": {
- "$ref": "#/components/schemas/EmbeddingTier"
- },
- "inherited": {
- "$ref": "#/components/schemas/EmbeddingTier"
- },
- "overrides": {
- "$ref": "#/components/schemas/EmbeddingTier"
- }
- }
- },
- "EmbeddingTier": {
- "type": "object",
- "properties": {
- "openai_api_base": {
- "type": "string"
- },
- "default_embedding_model": {
- "type": "string"
- },
- "openai_api_key_set": {
- "type": "boolean"
- }
- }
- },
- "Error": {
- "type": "object",
- "required": [
- "error"
- ],
- "properties": {
- "error": {
- "type": "object",
- "required": [
- "code",
- "message"
- ],
- "properties": {
- "code": {
- "type": "string",
- "description": "Stable machine-readable slug. Branch on THIS, never on the message."
- },
- "message": {
- "type": "string"
- },
- "details": {
- "type": "object",
- "additionalProperties": true,
- "description": "Present on some errors. For a duplicate: `field` (one) or `fields` (several), `values` (an object of colliding field/value pairs), `conflicting_document_id`, and `relation`/`current_version` where they apply."
- }
- }
- }
- }
- },
- "CollectionMeta": {
- "type": "object",
- "properties": {
- "relations_enforced": {
- "type": "boolean",
- "description": "Whether deletes from this collection are checked against the relations naming it as parent. Returned only on the single-collection GET, and ABSENT when the server could not determine it - absence never means disabled. Set it with PUT .../relations-enforced."
- },
- "name": {
- "type": "string"
- },
- "kind": {
- "type": "string",
- "enum": [
- "json",
- "vector"
- ]
- },
- "vector_dimension": {
- "type": "integer",
- "minimum": 1
- },
- "embedding_model": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- },
- "document_count": {
- "type": "integer",
- "description": "Live count, added by both collection reads."
- },
- "size_bytes": {
- "type": "integer",
- "description": "Live size, added by both collection reads."
- }
- },
- "required": [
- "name",
- "kind"
- ]
- },
- "KeyScopeRule": {
- "type": "object",
- "properties": {
- "collection": {
- "type": "string",
- "description": "Collection name the rule applies to"
- },
- "ops": {
- "type": "array",
- "items": {
- "type": "string",
- "enum": [
- "read",
- "list",
- "search",
- "insert",
- "update",
- "delete"
- ]
- },
- "description": "Permitted operations on this collection"
- },
- "require_human_token": {
- "type": "boolean",
- "description": "Phase 2: require a CAPTCHA token (reserved)"
- }
- },
- "required": [
- "collection",
- "ops"
- ]
- },
- "KeyScope": {
- "type": "object",
- "description": "Capability scope that constrains a non-admin key to specific collections and operations. A scoped key is safe to embed in untrusted clients (e.g. read-only, insert-only, origin-pinned, rate-limited, expiring). Scoped keys cannot manage collections or projects.",
- "properties": {
- "rules": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/KeyScopeRule"
- },
- "minItems": 1,
- "description": "At least one rule is required. A request is allowed only if a matching rule exists for the (collection, op) pair."
- },
- "origins": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "Allowed Origin header values. Empty array means any origin is permitted. When non-empty, requests without a matching Origin header are rejected (fails closed)."
- },
- "rate_limit_per_min": {
- "type": "integer",
- "minimum": 0,
- "description": "Maximum requests per minute for this key (keyed by key id). 0 means unlimited. Exceeding the limit returns 429 with a Retry-After: 60 header."
- },
- "expires_at": {
- "type": "integer",
- "description": "Unix epoch seconds after which the key is treated as expired (auth returns 401). 0 means the key never expires."
- }
- },
- "required": [
- "rules"
- ]
- },
- "ApiKeyPublic": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string",
- "description": "Stable non-secret identifier used to reference the key in PATCH/DELETE"
- },
- "key_prefix": {
- "type": "string"
- },
- "label": {
- "type": "string"
- },
- "projects": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "admin": {
- "type": "boolean"
- },
- "created_at": {
- "type": "integer"
- },
- "scope": {
- "$ref": "#/components/schemas/KeyScope",
- "description": "Present only when the key carries a capability scope"
- }
- }
- },
- "RelationDefinition": {
- "type": "object",
- "description": "Relation names are per-project and unqualified: the API always takes and returns bare names. The internal `project:` prefix used to store the relation is never exposed to clients.",
- "properties": {
- "name": {
- "type": "string"
- },
- "child": {
- "type": "string",
- "description": "Child collection name - holds the foreign reference"
- },
- "child_field": {
- "type": "string",
- "description": "Field on the child document that stores the parent's id"
- },
- "parent": {
- "type": "string",
- "description": "Parent collection name"
- },
- "on_delete": {
- "type": "string",
- "enum": [
- "restrict",
- "cascade",
- "set_null",
- "no_action"
- ]
- },
- "validate_on_write": {
- "type": "boolean"
- },
- "created_at": {
- "type": "integer"
- },
- "updated_at": {
- "type": "integer"
- }
- },
- "required": [
- "name",
- "child",
- "child_field",
- "parent",
- "on_delete"
- ]
- }
- },
- "responses": {
- "Conflict": {
- "description": "Conflict. `error.code` distinguishes the cases vectorapi returns 409 for: `duplicate_values` (a unique index refused the write, or an index could not be declared because the field already holds colliding values), `relation_restricted` (a document delete was blocked by a restrict relation) and `version_conflict` (a conditional write with ?if_version= found the document at another version).",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "error": {
- "type": "object",
- "properties": {
- "code": {
- "type": "string",
- "enum": [
- "duplicate_id",
- "duplicate_values",
- "relation_restricted",
- "version_conflict"
- ]
- },
- "message": {
- "type": "string"
- },
- "details": {
- "type": "object",
- "description": "Machine-readable payload. For `duplicate_values` on a document write: `field` (which unique index refused it), `value` (the colliding value, present when that field is at the top level of the submitted body) and `conflicting_document_id` (the document already holding it); all three are omitted if the database's message cannot be parsed, so test for them rather than assuming. For `duplicate_values` from POST /indexes: `duplicate_examples` (array of up to five document ids, one per colliding value). For `relation_restricted`: `impacts` (array of the same shape returned by GET .../documents/{id}/delete-impact). For `version_conflict`: `expected_version` and, when it could be read back, `current_version`.",
- "properties": {
- "field": {
- "type": "string"
- },
- "value": {
- "description": "The colliding value, as submitted. Any JSON type."
- },
- "conflicting_document_id": {
- "type": "string"
- },
- "expected_version": {
- "type": "integer"
- },
- "current_version": {
- "type": "integer"
- },
- "duplicate_examples": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "impacts": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "relation": {
- "type": "string"
- },
- "child_collection": {
- "type": "string"
- },
- "child_field": {
- "type": "string"
- },
- "on_delete": {
- "type": "string"
- },
- "child_count": {
- "type": "integer"
- },
- "sample_child_ids": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "blocks": {
- "type": "boolean"
- }
- }
- }
- }
- }
- }
- },
- "required": [
- "code",
- "message"
- ]
- }
- }
- }
- }
- }
- }
- }
- },
- "security": [
- {
- "bearerAuth": []
- }
- ],
- "paths": {
- "/healthz": {
- "get": {
- "summary": "Liveness check - always 200 if the process is running",
- "operationId": "healthz",
- "security": [],
- "responses": {
- "200": {
- "description": "OK"
- }
- }
- }
- },
- "/readyz": {
- "get": {
- "summary": "Readiness check - 200 when the database is reachable",
- "operationId": "readyz",
- "security": [],
- "responses": {
- "200": {
- "description": "Ready"
- },
- "503": {
- "description": "Database not reachable"
- }
- }
- }
- },
- "/api/v1/projects": {
- "get": {
- "summary": "List projects the key may access (admin sees all)",
- "operationId": "listProjects",
- "responses": {
- "200": {
- "description": "Project list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "projects": {
- "type": "array",
- "items": {
- "type": "string"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- }
- }
- },
- "post": {
- "summary": "Create a new project (admin only)",
- "operationId": "createProject",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- }
- },
- "required": [
- "name"
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Project created"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "422": {
- "description": "Validation error"
- }
- }
- }
- },
- "/api/v1/projects/{project}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "One project with its collection count",
- "operationId": "getProject",
- "responses": {
- "200": {
- "description": "Project info",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "collections": {
- "type": "integer",
- "description": "How many collections the project has. No document count is returned here - use /stats."
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Project not found"
- }
- }
- },
- "delete": {
- "summary": "Drop a project (admin only; not 'default')",
- "operationId": "deleteProject",
- "responses": {
- "200": {
- "description": "Project deleted"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "404": {
- "description": "Project not found"
- },
- "422": {
- "description": "Refusing to drop the `default` project (`protected`)"
- }
- }
- }
- },
- "/api/v1/keys": {
- "get": {
- "summary": "List API keys (admin only; secret masked; returns id and key_prefix)",
- "operationId": "listKeys",
- "responses": {
- "200": {
- "description": "Key list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "keys": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/ApiKeyPublic"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- },
- "post": {
- "summary": "Generate a new API key (admin only); returns the secret key value once",
- "operationId": "createKey",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "label": {
- "type": "string"
- },
- "projects": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "Project names the key may access; use [\"*\"] for all projects"
- },
- "admin": {
- "type": "boolean",
- "default": false
- },
- "scope": {
- "$ref": "#/components/schemas/KeyScope",
- "description": "Optional capability scope. Mutually exclusive with admin:true."
- }
- },
- "required": [
- "label",
- "projects"
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Key created; contains the secret key value (shown once) and the stable id",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string",
- "description": "Stable non-secret identifier for this key"
- },
- "key": {
- "type": "string",
- "description": "Secret key value - shown only once"
- },
- "label": {
- "type": "string"
- },
- "projects": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "admin": {
- "type": "boolean"
- },
- "scope": {
- "$ref": "#/components/schemas/KeyScope"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "422": {
- "description": "Validation error"
- }
- }
- }
- },
- "/api/v1/keys/{id}": {
- "parameters": [
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Stable non-secret key id (from the id field in list/create responses)"
- }
- ],
- "patch": {
- "summary": "Update key grants (admin only)",
- "operationId": "updateKey",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "label": {
- "type": "string"
- },
- "projects": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "admin": {
- "type": "boolean"
- },
- "scope": {
- "$ref": "#/components/schemas/KeyScope",
- "description": "Set or replace the capability scope. Omit to leave unchanged. Pass null to clear the scope."
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Key updated"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "404": {
- "description": "Key not found"
- }
- }
- },
- "delete": {
- "summary": "Revoke an API key (admin only)",
- "operationId": "deleteKey",
- "responses": {
- "200": {
- "description": "Key revoked"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "404": {
- "description": "Key not found"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "List collections in a project",
- "operationId": "listCollections",
- "parameters": [
- {
- "name": "q",
- "in": "query",
- "schema": {
- "type": "string"
- },
- "description": "Case-insensitive substring filter on collection name (applied server-side)."
- },
- {
- "name": "sort",
- "in": "query",
- "schema": {
- "type": "string",
- "enum": [
- "name",
- "kind",
- "documents",
- "size",
- "created_at"
- ],
- "default": "name"
- },
- "description": "Field to sort by (applied server-side). Ties break by name."
- },
- {
- "name": "desc",
- "in": "query",
- "schema": {
- "type": "boolean",
- "default": false
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Collection list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "collections": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/CollectionMeta"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- }
- }
- },
- "post": {
- "summary": "Create a collection in a project",
- "operationId": "createCollection",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "kind": {
- "type": "string",
- "enum": [
- "json",
- "vector"
- ]
- },
- "vector_dimension": {
- "type": "integer",
- "minimum": 1,
- "description": "Required when kind=vector"
- },
- "embedding_model": {
- "type": "string",
- "description": "Optional; defaults to global default_embedding_model"
- }
- },
- "required": [
- "name",
- "kind"
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Collection created"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "422": {
- "description": "Validation error (e.g. missing vector_dimension for vector kind)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- }
- ],
- "get": {
- "summary": "Get collection metadata",
- "operationId": "getCollection",
- "responses": {
- "200": {
- "description": "Collection metadata",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/CollectionMeta"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- }
- }
- },
- "delete": {
- "summary": "Drop a collection and all its documents",
- "operationId": "deleteCollection",
- "responses": {
- "200": {
- "description": "Collection deleted"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/documents": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- }
- ],
- "get": {
- "summary": "Find documents with optional filter, pagination, and sort",
- "operationId": "findDocuments",
- "parameters": [
- {
- "name": "filter",
- "in": "query",
- "schema": {
- "type": "string"
- },
- "description": "Filter expression in field:op:value grammar (e.g. age:gte:30, name:eq:Alice). Multiple filters are ANDed."
- },
- {
- "name": "limit",
- "in": "query",
- "schema": {
- "type": "integer",
- "default": 20
- }
- },
- {
- "name": "offset",
- "in": "query",
- "schema": {
- "type": "integer",
- "default": 0
- }
- },
- {
- "name": "sort",
- "in": "query",
- "schema": {
- "type": "string"
- },
- "description": "Field to sort by"
- },
- {
- "name": "desc",
- "in": "query",
- "schema": {
- "type": "boolean",
- "default": false
- }
- }
- ],
- "responses": {
- "200": {
- "description": "Document list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "documents": {
- "type": "array",
- "description": "Each row is the stored document plus the database's read-only metadata (_id, _version, _created_at, _updated_at, _created_by, _updated_by), the same shape a single GET returns. _version makes a filtered listing a usable starting point for a conditional write (?if_version=) without a second request per row.",
- "items": {
- "type": "object"
- }
- },
- "count": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- },
- "post": {
- "summary": "Insert a new JSON document",
- "operationId": "insertDocument",
- "parameters": [
- {
- "name": "X-Captcha-Token",
- "in": "header",
- "required": false,
- "schema": {
- "type": "string"
- },
- "description": "CAPTCHA response token. Required when the scoped key rule has require_human_token=true; verified server-side via the configured captcha provider."
- },
- {
- "name": "ttl_seconds",
- "in": "query",
- "required": false,
- "schema": {
- "type": "integer",
- "minimum": 0
- },
- "description": "Optional expiry, in seconds from now. Absent means the document has no expiry."
- }
- ],
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "description": "Either {\"data\":{...}} or the document itself; both store identical content. A `data` key alongside any other top-level field (other than `id`) returns 422 ambiguous_body instead of silently dropping those fields. To store a document whose own top-level field is called `data`, nest it once: {\"data\":{\"data\":...}}. `id` here is the document id, not a field, and is stripped from what is stored. The database's metadata fields (_id, _version, _created_at, _updated_at, _created_by, _updated_by) are stripped too, so a document read, edited and sent straight back does not store stale metadata as real fields.",
- "properties": {
- "id": {
- "type": "string",
- "description": "Optional document id; generated when omitted"
- },
- "data": {
- "type": "object",
- "description": "The document, when using the wrapper shape"
- }
- }
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Document inserted",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "422": {
- "description": "Validation error"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/documents/{id}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Document ID"
- }
- ],
- "get": {
- "summary": "Get a document by ID",
- "description": "Returns the stored document plus the database's read-only metadata. `_version` is the value ?if_version= takes on a conditional PUT or PATCH, so a read here is the first half of an optimistic-concurrency round trip; it is also returned as an ETag header.",
- "operationId": "getDocument",
- "responses": {
- "200": {
- "description": "Document",
- "headers": {
- "ETag": {
- "description": "The document's `_version`, quoted (e.g. \"7\"). Informational: conditional writes take the number in the ?if_version= query parameter, not an If-Match header.",
- "schema": {
- "type": "string"
- }
- }
- },
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "description": "The stored document's own fields, plus the metadata below. These six names are reserved by the database: a field of your own called _version can neither be stored nor read back.",
- "properties": {
- "_id": {
- "type": "string",
- "description": "The document id, the same value as in the path."
- },
- "_version": {
- "type": "integer",
- "description": "Starts at 1 and is incremented by every write. The value to send as ?if_version= on a conditional write."
- },
- "_created_at": {
- "type": "integer",
- "description": "Epoch milliseconds."
- },
- "_updated_at": {
- "type": "integer",
- "description": "Epoch milliseconds."
- },
- "_created_by": {
- "type": "string"
- },
- "_updated_by": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Document not found"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- },
- "put": {
- "summary": "Replace a document by ID, creating it when absent (upsert)",
- "description": "PUT stores the document at the id in the path whether or not it already exists, which is what the method means and what lets a client key records by an id it receives from elsewhere (an external call id, say) without probing first. A replace is not a merge: fields the body omits are dropped. Creating counts as an insert for authorization, so a capability-scoped key granted `update` but not `insert` on the collection may only replace and gets 403 on an id that does not exist yet. PATCH, unlike PUT, never creates. PUT takes no ttl_seconds: create with an expiry via POST with an `id`.",
- "operationId": "replaceDocument",
- "parameters": [
- {
- "name": "if_version",
- "in": "query",
- "required": false,
- "schema": {
- "type": "integer",
- "minimum": 1
- },
- "description": "Conditional write: apply only if the document is still at this version (read it as `_version` from a GET or a listing). On a mismatch the write is refused with 409 version_conflict and error.details.expected_version / current_version. Must be a positive integer - versions start at 1, so 0 is rejected with 422 rather than read as \"must not exist\". A conditional write never creates: if_version against an absent document is 404."
- }
- ],
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "description": "Either {\"data\":{...}} or the document itself; both store identical content. A `data` key alongside any other top-level field (other than `id`) returns 422 ambiguous_body instead of silently dropping those fields. To store a document whose own top-level field is called `data`, nest it once: {\"data\":{\"data\":...}}. An `id` in the body is ignored: the URL supplies it. The database's metadata fields (_id, _version, _created_at, _updated_at, _created_by, _updated_by) are stripped, so a document read and sent straight back does not store stale metadata as real fields."
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Document replaced",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "created": {
- "type": "boolean",
- "description": "false on this status."
- },
- "version": {
- "type": "integer",
- "description": "The document's version after this write."
- }
- }
- }
- }
- }
- },
- "201": {
- "description": "Document created at the given id",
- "headers": {
- "Location": {
- "description": "The document's URL, the same as the request target.",
- "schema": {
- "type": "string"
- }
- }
- },
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "created": {
- "type": "boolean",
- "description": "true on this status."
- },
- "version": {
- "type": "integer",
- "description": "1: a newly created document."
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden (including a scope that permits update but not insert, on a PUT that would create)"
- },
- "404": {
- "description": "Collection not found, or ?if_version= was sent for a document that does not exist"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "422": {
- "description": "Validation error"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- },
- "patch": {
- "summary": "Partially update a document (merge fields)",
- "description": "An RFC 7396 merge patch: the fields in the body are merged into the stored document and a null removes a field. 404 when the document does not exist - PATCH never creates, because merging fields into nothing has no defined result and a patch body is not a whole document. Use PUT to create.",
- "operationId": "patchDocument",
- "parameters": [
- {
- "name": "if_version",
- "in": "query",
- "required": false,
- "schema": {
- "type": "integer",
- "minimum": 1
- },
- "description": "Conditional write: merge only if the document is still at this version (read it as `_version` from a GET or a listing). On a mismatch: 409 version_conflict with error.details.expected_version / current_version. Must be a positive integer (422 otherwise). Two combinations are refused with 422 conditional_unsupported rather than approximated: together with ttl_seconds (a version-checked write carries no expiry), and on a kind=vector collection (it rewrites the whole document, which would drop the stored embedding)."
- },
- {
- "name": "ttl_seconds",
- "in": "query",
- "required": false,
- "schema": {
- "type": "integer",
- "minimum": 0
- },
- "description": "Sets the document's expiry, in seconds from now. This parameter is asymmetric by design: **omitting it leaves the document's current expiry untouched**; sending `ttl_seconds=0` **clears** the expiry, making the document permanent. Do not assume 0 means \"no TTL requested\": it actively wipes an existing one."
- }
- ],
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "description": "Either {\"data\":{...}} or the document itself; both store identical content. A `data` key alongside any other top-level field (other than `id`) returns 422 ambiguous_body instead of silently dropping those fields. To store a document whose own top-level field is called `data`, nest it once: {\"data\":{\"data\":...}}. PATCH merges the fields INSIDE the wrapper, not a field called `data`. An `id` in the body is ignored: the URL supplies it. The database's metadata fields (_id, _version, _created_at, _updated_at, _created_by, _updated_by) are stripped."
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Document updated",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "version": {
- "type": "integer",
- "description": "The document's version after this write."
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Document not found"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "422": {
- "description": "Validation error, including conditional_unsupported for if_version with ttl_seconds or on a vector collection"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- },
- "delete": {
- "summary": "Delete a document by ID",
- "description": "Fails with 409 relation_restricted when a restrict relation has children referencing this document (see GET .../delete-impact to preview this beforehand without deleting).",
- "operationId": "deleteDocument",
- "responses": {
- "200": {
- "description": "Document deleted"
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Document not found"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/documents/{id}/increment": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Document ID"
- }
- ],
- "post": {
- "summary": "Atomically add to one or more numeric fields",
- "operationId": "incrementDocument",
- "description": "Adds each number in the body to the named field in ONE locked server-side read-modify-write, and answers with the new values. Concurrent increments therefore cannot lose each other, which a read-add-write cannot promise however carefully it is version-checked. An absent or null field counts as 0. Integer + integer stays an integer (overflow is refused); anything else becomes a double. A field holding a non-number is 422 and NOTHING is applied - the whole set applies or none of it does.\n\nA separate route rather than a flag on PATCH, because a PATCH body and an increment body look identical and mean opposite things: {\"calls\": 1} is \"set calls to 1\" on PATCH and \"add 1 to calls\" here, and one body shape with two meanings decided by a query parameter is how a forgotten parameter silently resets a counter.\n\nAuthorization is the collection's `update` grant: it is a write, so a scope granting only `read` gets 403, and it is specifically an update because the document must already exist. It grants nothing `update` did not - a caller that may replace a document may already set any number to any value.\n\nThe document must exist: this route never creates one, because the starting document is the caller's to describe. The idiom for a counter that may not exist yet is to increment, on 404 POST the document under a fixed id with its starting values, and on 409 duplicate_values (another writer just created it) increment again.",
- "requestBody": {
- "required": true,
- "description": "The deltas, as field -> number. A dotted key addresses a nested field (`counts.sent`). Accepts the same two body shapes as a document write: the deltas on their own, or wrapped as {\"data\": {...}} - and `data` beside any other top-level key is 422 ambiguous_body, exactly as on POST/PUT/PATCH.",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "minProperties": 1,
- "additionalProperties": {
- "type": "number"
- },
- "example": {
- "calls": 1,
- "minutes": 3.5
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Applied; the new values of every field named",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "values": {
- "type": "object",
- "additionalProperties": {
- "type": "number"
- },
- "description": "The NEW value of each field that was incremented. Returned in the response rather than left to a follow-up GET: a caller that has to re-read to learn its own result has lost the atomicity it came here for.",
- "example": {
- "calls": 18,
- "minutes": 61.5
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - the collection's `update` grant is required"
- },
- "404": {
- "description": "No such collection, or no such document (this route never creates one)"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "422": {
- "description": "Validation error: an empty body, a non-numeric or non-finite delta, a field path with an empty segment, or `data` beside other top-level keys. Nothing was applied."
- },
- "503": {
- "description": "Database unavailable, read-only, or under memory pressure"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/documents/{id}/delete-impact": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Document ID"
- }
- ],
- "get": {
- "summary": "Preview what deleting this document would affect, without deleting it",
- "description": "Read-only: changes nothing. Reports whether a delete would be blocked and, for every relation where this collection is the parent, the child collection, the count of referencing child documents, up to a handful of sample child ids, and whether that particular relation blocks the delete. Follows the collection's read grant, so a scoped key with a read rule on this collection may call it (index/relation management routes are admin/full-key only, but this one is not).",
- "operationId": "describeDelete",
- "responses": {
- "200": {
- "description": "Delete impact preview",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "would_be_blocked": {
- "type": "boolean"
- },
- "impacts": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "relation": {
- "type": "string"
- },
- "child_collection": {
- "type": "string"
- },
- "child_field": {
- "type": "string"
- },
- "on_delete": {
- "type": "string",
- "enum": [
- "restrict",
- "cascade",
- "set_null",
- "no_action"
- ]
- },
- "child_count": {
- "type": "integer"
- },
- "sample_child_ids": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "blocks": {
- "type": "boolean"
- }
- }
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Document not found"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/indexes": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- }
- ],
- "delete": {
- "summary": "Drop a composite unique constraint",
- "operationId": "dropCompositeUniqueIndex",
- "description": "Drops the composite unique constraint over the EXACT set of fields named. Repeat the `fields` parameter once per field; order does not matter. The field list lives in a query parameter rather than a path segment because joining it would need a separator that no field name may contain, and a reserved segment under .../indexes/{field} would shadow a real field of that name. Single-field indexes are dropped with DELETE .../indexes/{field} instead. Requires a full (non-scoped) key with project access; scoped keys cannot manage indexes.",
- "parameters": [
- {
- "name": "fields",
- "in": "query",
- "required": true,
- "explode": true,
- "style": "form",
- "schema": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "minItems": 2
- },
- "description": "Every field of the composite constraint, one `fields` parameter each. An empty or single-field list is 422: this route never means \"drop everything\"."
- }
- ],
- "responses": {
- "200": {
- "description": "Constraint dropped, or already absent - the drop is idempotent",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "dropped_fields": {
- "type": "array",
- "items": {
- "type": "string"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - project access required; scoped keys cannot manage indexes"
- },
- "422": {
- "description": "Validation error (fields missing, repeated, or naming fewer than two fields)"
- },
- "503": {
- "description": "The database did not apply the drop (`unavailable`)"
- }
- }
- },
- "post": {
- "summary": "Declare a field index, optionally unique; backfills existing rows",
- "description": "Backfills existing rows as part of the call, so the index is usable immediately once this returns. Idempotent: re-declaring an index that already exists on `field` reports already_existed:true instead of erroring. Requires a full (non-scoped) key with project access; scoped keys cannot manage indexes.",
- "operationId": "createIndex",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "description": "Either a single-field index (`field`) or a composite unique constraint (`fields`). The two are two spellings of one request and are mutually exclusive: a body carrying BOTH is 422 ambiguous_body, never resolved by precedence.",
- "oneOf": [
- {
- "type": "object",
- "properties": {
- "field": {
- "type": "string"
- },
- "unique": {
- "type": "boolean",
- "default": false,
- "description": "When true, enforces a uniqueness constraint. If the field already holds duplicate values across existing documents, the call fails with 409 duplicate_values instead of creating the index."
- }
- },
- "required": [
- "field"
- ]
- },
- {
- "type": "object",
- "description": "A COMPOSITE unique constraint: no two documents may hold the same COMBINATION of these fields, e.g. [\"chat_id\", \"file_unique_id\"]. A document in which ANY of the fields is absent or null does not participate, which is the SQL rule for a NULL in a unique key. Declaring it over existing duplicates fails with 409 duplicate_values and up to five colliding document ids in error.details.duplicate_examples. It backs no query: it is a constraint, not an index a filter can use.",
- "properties": {
- "fields": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "minItems": 2,
- "uniqueItems": true,
- "description": "Two or more field names, each named once. A dotted name addresses a nested field. One field is not a composite - use `field` instead - and a repeated field is refused, because the database identifies a composite by its exact list."
- },
- "unique": {
- "type": "boolean",
- "enum": [
- true
- ],
- "description": "Implied and may be omitted. A composite exists only as a unique constraint, so an explicit false is 422 rather than a constraint the caller believes it declined."
- }
- },
- "required": [
- "fields"
- ]
- }
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Index declared",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "fields": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "Returned instead of `field` when a composite constraint was declared."
- },
- "field": {
- "type": "string"
- },
- "unique": {
- "type": "boolean"
- },
- "rows_indexed": {
- "type": "integer"
- },
- "already_existed": {
- "type": "boolean"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - project access required; scoped keys cannot manage indexes"
- },
- "404": {
- "description": "Collection not found"
- },
- "409": {
- "$ref": "#/components/responses/Conflict"
- },
- "422": {
- "description": "Validation error (missing field)"
- }
- }
- },
- "get": {
- "summary": "List indexes declared on a collection",
- "operationId": "listIndexes",
- "responses": {
- "200": {
- "description": "Index list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "composite_unique": {
- "type": "array",
- "description": "The composite unique constraints declared on the collection. A separate key rather than extra entries in `indexes`, which keeps exactly its existing shape: a composite backs no query, so it has no distinct_values or entries, and it is named by a field LIST rather than by a field.",
- "items": {
- "type": "object",
- "properties": {
- "fields": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "unique": {
- "type": "boolean",
- "enum": [
- true
- ]
- }
- }
- }
- },
- "indexes": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "field": {
- "type": "string"
- },
- "distinct_values": {
- "type": "integer"
- },
- "entries": {
- "type": "integer"
- },
- "unique": {
- "type": "boolean"
- }
- }
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/indexes/{field}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- },
- {
- "name": "field",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Indexed field name"
- }
- ],
- "delete": {
- "summary": "Drop an index",
- "operationId": "dropIndex",
- "description": "Requires a full (non-scoped) key with project access; scoped keys cannot manage indexes.",
- "responses": {
- "200": {
- "description": "Index dropped",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "dropped": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - project access required; scoped keys cannot manage indexes"
- },
- "503": {
- "description": "The database did not apply the drop (`unavailable`)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/indexes/{field}/values": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- },
- {
- "name": "field",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Indexed field name"
- }
- ],
- "get": {
- "summary": "Distinct values of an indexed field, with per-value counts",
- "description": "Index-dependent by design, not an error: returns an empty values list with HTTP 200 when `field` has no index, and also for array-valued fields, whose index keys are the individual array elements rather than the field's own value. Follows the collection's read grant, so a scoped key with a read rule on this collection may call it. Use order=desc&limit=1 to get the maximum value.",
- "operationId": "indexFieldValues",
- "parameters": [
- {
- "name": "limit",
- "in": "query",
- "schema": {
- "type": "integer",
- "minimum": 1,
- "maximum": 1000,
- "default": 100
- },
- "description": "Maximum number of distinct values to return, 1-1000."
- },
- {
- "name": "order",
- "in": "query",
- "schema": {
- "type": "string",
- "enum": [
- "asc",
- "desc"
- ],
- "default": "asc"
- },
- "description": "Sort order of the returned values."
- }
- ],
- "responses": {
- "200": {
- "description": "Distinct values with counts (possibly empty; see description)",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "values": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "value": {},
- "count": {
- "type": "integer"
- }
- }
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "422": {
- "description": "Validation error (limit out of 1..1000 range or non-numeric)"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/relations-enforced": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name"
- }
- ],
- "put": {
- "summary": "Enable or disable relation enforcement on a collection (admin only)",
- "description": "IMPORTANT: relations_enforced is read on the collection you are deleting FROM, i.e. the PARENT side of the relation, not on the child collection that holds the foreign reference. Disabling it on the child has no effect on deletes issued against the parent. To allow deletes on a parent collection to bypass restrict relations, set this flag on the parent, not the child.",
- "operationId": "setRelationsEnforced",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "enforced": {
- "type": "boolean"
- }
- },
- "required": [
- "enforced"
- ]
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Enforcement flag updated",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "collection": {
- "type": "string"
- },
- "enforced": {
- "type": "boolean"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "422": {
- "description": "Validation error (enforced missing or not a boolean)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/vectors": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name (must be kind=vector)"
- }
- ],
- "post": {
- "summary": "Store a vector; supply either text (auto-embedded) or an explicit vector array",
- "description": "Store a vector. Supply either `text` (auto-embedded) or a pre-computed `vector` array. When supplying `text`, the server-side embedding result is cached by default. Send `Cache-Control: no-store` to bypass the cache: the text will be re-embedded fresh and the result will not be stored.",
- "operationId": "upsertVector",
- "parameters": [
- {
- "name": "X-Captcha-Token",
- "in": "header",
- "required": false,
- "schema": {
- "type": "string"
- },
- "description": "CAPTCHA response token. Required when the scoped key rule has require_human_token=true; verified server-side via the configured captcha provider."
- }
- ],
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string",
- "description": "Optional stable ID; auto-generated if omitted"
- },
- "text": {
- "type": "string",
- "description": "Source text; will be embedded using the collection's embedding_model"
- },
- "vector": {
- "type": "array",
- "items": {
- "type": "number"
- },
- "description": "Pre-computed embedding; dimension must match the collection's vector_dimension"
- },
- "metadata": {
- "type": "object",
- "description": "Arbitrary JSON payload stored alongside the vector"
- }
- }
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Vector stored",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- },
- "422": {
- "description": "Validation error (wrong dimension, not a vector collection, etc.)"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/collections/{name}/search": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Collection name (must be kind=vector)"
- }
- ],
- "post": {
- "summary": "Cosine-similarity search; supply either query_text (auto-embedded) or query_vector",
- "description": "Supply either `query_text` or `query_vector`. **For low latency, prefer `query_vector`.** `query_text` requires a synchronous server-side embedding round-trip to the configured provider, which typically dominates request latency (seconds for large models). Clients issuing many searches (e.g. an LLM/n8n agent) should embed once on their side and pass `query_vector` to skip that step entirely; cosine search itself is sub-millisecond. Send `Cache-Control: no-store` to bypass the server-side embedding cache: the query text will be re-embedded fresh and the result will not be stored.",
- "operationId": "searchVectors",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "query_text": {
- "type": "string",
- "description": "Query text; embedded with the collection's model. Slow path: incurs a server-side embedding round-trip. Prefer query_vector when you can pre-embed."
- },
- "query_vector": {
- "type": "array",
- "items": {
- "type": "number"
- },
- "description": "Pre-computed query embedding (length must equal the collection's vector_dimension). Fast path: skips server-side embedding."
- },
- "top_k": {
- "type": "integer",
- "minimum": 1,
- "default": 5,
- "description": "Maximum number of results to return (default 5)"
- },
- "min_score": {
- "type": "number",
- "default": 0,
- "description": "Minimum cosine similarity score (0-1), default 0"
- },
- "filters": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "description": "Metadata filters in field:op:value grammar, ANDed (e.g. src:eq:n8n). Same operators as the documents endpoint (eq, ne, lt, lte, gt, gte, in, contains, exists, regex, search) and evaluated by the database, so a document scores the same with or without a filter. Metadata is stored at the document top level: metadata {\"colour\":\"red\"} is filtered as colour:eq:red. Note that contains is array membership - use search for substrings. A malformed spec or unknown operator returns 400 bad_filter. The filtered scan is bounded at 10000 candidates."
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Search results",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "results": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "id": {
- "type": "string"
- },
- "score": {
- "type": "number"
- },
- "data": {
- "type": "object",
- "additionalProperties": true,
- "description": "The stored document. Named `data`, not `metadata`. The stored vector is NOT included - no read returns it."
- }
- }
- }
- },
- "scan_capped": {
- "type": "boolean",
- "description": "True when the filtered walk stopped at the candidate scan cap while still short of top_k, so MORE rows may match than were returned. False means the answer is complete, including a filter that simply matches fewer rows than top_k. Check it before treating a filtered result set as exhaustive."
- },
- "scanned": {
- "type": "integer",
- "description": "How deep into the ranking the walk went. Absent for an unfiltered search."
- },
- "scan_cap": {
- "type": "integer",
- "description": "The cap that was hit. Present only when scan_capped is true."
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- },
- "404": {
- "description": "Collection not found"
- },
- "422": {
- "description": "Validation error"
- },
- "429": {
- "description": "Too Many Requests (rate-limited scoped key)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/stats": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "Per-project stats (accessible by any key granted the project)",
- "operationId": "projectStats",
- "responses": {
- "200": {
- "description": "Project stats",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "project": {
- "type": "string"
- },
- "collections": {
- "type": "integer"
- },
- "documents": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden"
- }
- }
- }
- },
- "/api/v1/projects/{project}/relations": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "post": {
- "summary": "Create a relation between two collections in a project (admin only)",
- "description": "Relation names are per-project and unqualified: the API takes and returns bare names - the internal project: prefix used to store the relation is never exposed. name may not start with _ or the reserved vectorapi_ prefix.",
- "operationId": "createRelation",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string",
- "description": "Unqualified relation name"
- },
- "child": {
- "type": "string",
- "description": "Child collection name - holds the foreign reference"
- },
- "child_field": {
- "type": "string",
- "description": "Field on the child document that stores the parent's id"
- },
- "parent": {
- "type": "string",
- "description": "Parent collection name"
- },
- "on_delete": {
- "type": "string",
- "enum": [
- "restrict",
- "cascade",
- "set_null",
- "no_action"
- ],
- "default": "restrict",
- "description": "Any value outside this set is rejected with 422."
- },
- "validate_on_write": {
- "type": "boolean",
- "default": false,
- "description": "When true, writes to the child are validated against an existing parent."
- }
- },
- "required": [
- "name",
- "child",
- "child_field",
- "parent"
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Relation created",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RelationDefinition"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "422": {
- "description": "Validation error (missing field, or on_delete not one of restrict/cascade/set_null/no_action)"
- }
- }
- },
- "get": {
- "summary": "List relations defined in a project (admin only)",
- "operationId": "listRelations",
- "responses": {
- "200": {
- "description": "Relation list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "relations": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/RelationDefinition"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- }
- },
- "/api/v1/projects/{project}/relations/{name}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Unqualified relation name"
- }
- ],
- "get": {
- "summary": "Get a relation by name (admin only)",
- "operationId": "getRelation",
- "responses": {
- "200": {
- "description": "Relation",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/RelationDefinition"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "404": {
- "description": "Relation not found"
- }
- }
- },
- "delete": {
- "summary": "Drop a relation by name (admin only)",
- "operationId": "dropRelation",
- "responses": {
- "200": {
- "description": "Relation dropped",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "dropped": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "404": {
- "description": "Relation not found"
- }
- }
- }
- },
- "/api/v1/projects/{project}/settings/functions": {
- "get": {
- "tags": [
- "Settings"
- ],
- "summary": "Per-project function limits",
- "description": "The project's wall-time cap, per run kind: {\"max_wall_time_ms\": {\"http\": n|null, \"job\": n|null}}. Always the object form - a single number cannot express \"10s for routes, 60s for jobs\", and keeping the old scalar would let a client that reads only it see null (no cap) while a cap was in force.",
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "description": "The per-kind cap"
- },
- "403": {
- "description": "Not an admin key.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- },
- "put": {
- "tags": [
- "Settings"
- ],
- "summary": "Set the per-project function wall-time cap",
- "description": "Admin only, because it decides how long one project may hold a pooled runtime - and therefore how long it can delay every other project's interactive routes. Send null to inherit.",
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "max_wall_time_ms": {
- "oneOf": [
- {
- "type": "integer",
- "minimum": 1,
- "description": "Sets BOTH kinds - the pre-0.6.0 spelling, still honoured."
- },
- {
- "type": "null",
- "description": "Clears both kinds."
- },
- {
- "type": "object",
- "properties": {
- "http": {
- "type": "integer",
- "nullable": true,
- "minimum": 1
- },
- "job": {
- "type": "integer",
- "nullable": true,
- "minimum": 1
- }
- },
- "additionalProperties": false
- }
- ],
- "description": "A bare integer sets both kinds; null clears both; an object sets only the keys it names. Narrowing only - neither raises a ceiling."
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "The per-kind cap"
- },
- "403": {
- "description": "Not an admin key.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "422": {
- "description": "Not an integer or null.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- }
- },
- "/api/v1/projects/{project}/settings/embeddings": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "Get this project's embedding settings: effective, inherited and overridden values. The API key is never returned, only openai_api_key_set.",
- "operationId": "getProjectEmbeddingSettings",
- "responses": {
- "200": {
- "description": "Project embedding settings",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/ProjectEmbeddingSettings"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- }
- },
- "description": "Returns {effective, inherited, overrides}; each carries openai_api_base, default_embedding_model, openai_api_key_set, embedding_connect_timeout_sec and embedding_read_timeout_sec. The API key itself is never returned."
- },
- "put": {
- "summary": "Set or clear this project's embedding overrides. Omit a field to leave it unchanged; send null to clear it and inherit the global value.",
- "operationId": "updateProjectEmbeddingSettings",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "openai_api_base": {
- "type": [
- "string",
- "null"
- ],
- "description": "Must start with http:// or https://. Empty string is rejected; send null to inherit the global value"
- },
- "openai_api_key": {
- "type": [
- "string",
- "null"
- ],
- "description": "Write-only, never returned. Empty string is rejected; send null to inherit the global key"
- },
- "default_embedding_model": {
- "type": [
- "string",
- "null"
- ],
- "description": "Empty string is rejected; send null to inherit the global default"
- },
- "embedding_connect_timeout_sec": {
- "type": "integer",
- "nullable": true,
- "minimum": 1,
- "description": "Seconds. Narrowing only: effective = min(project, global). null inherits the global value."
- },
- "embedding_read_timeout_sec": {
- "type": "integer",
- "nullable": true,
- "minimum": 1,
- "description": "Seconds. Narrowing only: effective = min(project, global). null inherits the global value."
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Updated project embedding settings",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/ProjectEmbeddingSettings"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "422": {
- "description": "Validation failed: empty value, malformed base URL, or openai_api_base without openai_api_key for the same project (code embedding_base_requires_key)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- },
- "description": "Omit a field to leave it unchanged; null clears an override. The two timeouts are narrowing only - a project can tighten how long it may hold a shared provider connection but never lengthen it. A value above the global one is stored rather than refused, and becomes effective if an operator later lowers the global."
- },
- "delete": {
- "summary": "Drop every override so the project inherits the global embedding settings again",
- "operationId": "deleteProjectEmbeddingSettings",
- "responses": {
- "200": {
- "description": "Overrides removed",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "reverted": {
- "type": "string"
- },
- "had_overrides": {
- "type": "boolean"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- }
- },
- "description": "Drops every embedding override, the timeouts included. Deliberately does NOT touch the project's function policy or wall-time caps, which share the document but are admin-only."
- }
- },
- "/api/v1/projects/{project}/secrets": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "List this project's function secrets by name. Values are never returned - only the name, whether a value is set, and the timestamps.",
- "description": "Project-manage: a function author needs to know which names their code may read as ctx.env.<NAME>.",
- "operationId": "listProjectSecrets",
- "responses": {
- "200": {
- "description": "Secret names",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "project": {
- "type": "string"
- },
- "secrets": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/ProjectSecret"
- }
- },
- "count": {
- "type": "integer"
- },
- "max_secrets": {
- "type": "integer"
- },
- "max_value_bytes": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such project"
- }
- }
- }
- },
- "/api/v1/projects/{project}/secrets/{name}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string",
- "pattern": "^[A-Z_][A-Z0-9_]*$",
- "maxLength": 64
- },
- "description": "Secret name, an environment-variable-style identifier. Reaches the project's functions as ctx.env.<NAME>."
- }
- ],
- "get": {
- "summary": "Whether this secret is set. The value is never returned by any endpoint.",
- "operationId": "getProjectSecret",
- "responses": {
- "200": {
- "description": "Secret metadata",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/ProjectSecret"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such project or secret"
- },
- "422": {
- "description": "Invalid secret name"
- }
- }
- },
- "put": {
- "summary": "Set or rotate one secret (admin only). Write-only: the value is never readable again.",
- "description": "The value reaches this project's functions as ctx.env.<NAME>. A host variable SVAPI_FN_<project>__<NAME> in the runner's environment takes precedence over the stored value of the same name.",
- "operationId": "putProjectSecret",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "required": [
- "value"
- ],
- "properties": {
- "value": {
- "type": "string",
- "minLength": 1,
- "maxLength": 8192,
- "description": "Write-only, never returned. Empty is rejected; DELETE the secret to remove it."
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Secret rotated",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/ProjectSecret"
- }
- }
- }
- },
- "201": {
- "description": "Secret created",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/ProjectSecret"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin only"
- },
- "404": {
- "description": "No such project"
- },
- "422": {
- "description": "Validation failed: bad name, empty or oversized value, or the project is at its secret limit (code secret_limit)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- },
- "delete": {
- "summary": "Delete one secret (admin only)",
- "operationId": "deleteProjectSecret",
- "responses": {
- "200": {
- "description": "Secret deleted",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "deleted": {
- "type": "string"
- },
- "project": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin only"
- },
- "404": {
- "description": "No such project or secret"
- },
- "422": {
- "description": "Invalid secret name"
- }
- }
- }
- },
- "/fn/{project}/{path}": {
- "description": "Public dispatch for a project's HTTP functions. Unauthenticated by design: a published function's route is public. The project is the first path segment; the remainder is matched against that project's declared routes.",
- "get": {
- "$ref": "#/components/pathItems/FunctionDispatch/get"
- },
- "post": {
- "$ref": "#/components/pathItems/FunctionDispatch/get"
- },
- "put": {
- "$ref": "#/components/pathItems/FunctionDispatch/get"
- },
- "patch": {
- "$ref": "#/components/pathItems/FunctionDispatch/get"
- },
- "delete": {
- "$ref": "#/components/pathItems/FunctionDispatch/get"
- }
- },
- "/api/v1/projects/{project}/functions": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- }
- ],
- "get": {
- "summary": "List this project's functions, without their sources",
- "operationId": "listFunctions",
- "responses": {
- "200": {
- "description": "Function list",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "functions": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/FunctionSummary"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- }
- }
- },
- "post": {
- "summary": "Register a new function. The source is compiled on a runner BEFORE it is stored, and its id comes from the script's `on` block - not from this request.",
- "description": "The id is read from the validated descriptor, so there is no `function_id` field to send. A `policy` field is ignored: policy is server state, changed only by an admin through PUT .../functions/{id}/policy. A first registration inherits the project's default policy, which currently grants no collection at all.",
- "operationId": "createFunction",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "source": {
- "type": "string",
- "description": "The JavaScript module. Must export an `on` object declaring at least an id."
- },
- "path": {
- "type": "string",
- "description": "Where the author keeps the file. Stored as-is and never used as an identity."
- }
- },
- "required": [
- "source"
- ]
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Function stored",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/FunctionSummary"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "409": {
- "description": "A function with this id already exists (code function_exists) - PUT it to update",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "422": {
- "description": "The source did not compile (code compile_failed), the `on` block declares no id (code missing_function_id), or `source` is missing (code validation)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "503": {
- "description": "No healthy runner to validate against (code no_runner / runner_unreachable). Code is never stored unvalidated.",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- }
- },
- "/api/v1/projects/{project}/functions/{id}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The function id declared in the script's `on` block"
- }
- ],
- "get": {
- "summary": "Get one function, including its source",
- "operationId": "getFunction",
- "responses": {
- "200": {
- "description": "The function",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Function"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such function"
- }
- }
- },
- "put": {
- "summary": "Push code to this function. Validated on a runner first, and the stored policy and enabled flag are preserved - a code push can never widen access.",
- "description": "The id in the URL must equal the id the script declares; a mismatch is 422 rather than a rename, because the URL would otherwise move code onto another function's policy. A PUT to an unused id registers it (201).",
- "operationId": "updateFunction",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "source": {
- "type": "string"
- },
- "path": {
- "type": "string"
- }
- },
- "required": [
- "source"
- ]
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Function updated",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/FunctionSummary"
- }
- }
- }
- },
- "201": {
- "description": "Function registered (the id was unused)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/FunctionSummary"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "422": {
- "description": "The source did not compile (code compile_failed), declares no id (code missing_function_id), or declares an id other than the one in the URL (code id_mismatch, with details.declared and details.url)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "503": {
- "description": "No healthy runner to validate against (code no_runner / runner_unreachable)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- },
- "delete": {
- "summary": "Delete a function, its code and its policy",
- "operationId": "deleteFunction",
- "responses": {
- "200": {
- "description": "Deleted",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "deleted": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such function"
- }
- }
- }
- },
- "/api/v1/projects/{project}/functions/{id}/policy": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The function id declared in the script's `on` block"
- }
- ],
- "put": {
- "summary": "Replace what this function may touch (ADMIN ONLY). The only route that changes a policy.",
- "description": "Developers push code, admins grant access - the same split API keys already have, which is why this route is admin-only while the rest of the function routes are not. An empty rule set is accepted and means the function reaches no collection.",
- "operationId": "setFunctionPolicy",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "description": "Either {\"policy\": {...}} or the policy object itself.",
- "properties": {
- "policy": {
- "$ref": "#/components/schemas/FunctionPolicy"
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Policy replaced",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/FunctionSummary"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires an admin key"
- },
- "404": {
- "description": "No such function"
- },
- "422": {
- "description": "Malformed policy: a rule without a collection or ops, or an unknown op (code validation)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- }
- },
- "/api/v1/projects/{project}/functions/{id}/enabled": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The function id declared in the script's `on` block"
- }
- ],
- "put": {
- "summary": "Enable or disable a function. Server state: a later code push does not re-enable it.",
- "operationId": "setFunctionEnabled",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "enabled": {
- "type": "boolean"
- }
- },
- "required": [
- "enabled"
- ]
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Updated",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "function_id": {
- "type": "string"
- },
- "enabled": {
- "type": "boolean"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such function"
- },
- "422": {
- "description": "`enabled` missing or not a boolean (code validation)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/functions/{id}/invoke": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The function id declared in the script's `on` block"
- }
- ],
- "post": {
- "summary": "Run a function once with a synthesised trigger, and record the run",
- "description": "Every field of the body is optional: an empty body invokes the function with its own route as the path and POST as the method. The call answers 200 whenever the run was PERFORMED, even if the function itself failed - its status, error and console output are in the envelope. The run is appended to the function's log either way.",
- "operationId": "invokeFunction",
- "requestBody": {
- "required": false,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "method": {
- "type": "string",
- "description": "Defaults to POST"
- },
- "path": {
- "type": "string",
- "description": "Defaults to the route the descriptor declares"
- },
- "params": {
- "type": "object",
- "description": "ctx.params - what a real route match would have captured",
- "additionalProperties": {
- "type": "string"
- }
- },
- "query": {
- "type": "object",
- "description": "ctx.query",
- "additionalProperties": {
- "type": "string"
- }
- },
- "headers": {
- "type": "object",
- "additionalProperties": {
- "type": "string"
- }
- },
- "body": {
- "description": "ctx.body; any JSON type"
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "The run was performed; the envelope says what the function did",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/FunctionRunResult"
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such function"
- },
- "409": {
- "description": "The function is disabled (code function_disabled) or marked invalid (code function_invalid)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- },
- "503": {
- "description": "No healthy runner (code no_runner), or no runner could be reached for this run (code runner_unreachable, with details.run_id - the failed attempt is still logged)",
- "content": {
- "application/json": {
- "schema": {
- "$ref": "#/components/schemas/Error"
- }
- }
- }
- }
- }
- }
- },
- "/api/v1/projects/{project}/functions/{id}/logs": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "Project name"
- },
- {
- "name": "id",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- },
- "description": "The function id declared in the script's `on` block"
- }
- ],
- "get": {
- "summary": "This function's recorded runs, newest first",
- "description": "The log keeps only the newest N runs per function (trimmed on every write), so a limit above N returns N.",
- "operationId": "listFunctionRuns",
- "parameters": [
- {
- "name": "limit",
- "in": "query",
- "required": false,
- "schema": {
- "type": "integer",
- "minimum": 1
- },
- "description": "Maximum runs to return; defaults to 50 and is clamped to how many the server keeps"
- }
- ],
- "responses": {
- "200": {
- "description": "Run log",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "function_id": {
- "type": "string"
- },
- "runs": {
- "type": "array",
- "items": {
- "$ref": "#/components/schemas/FunctionRun"
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - requires a key granted this project; capability-scoped keys are refused"
- },
- "404": {
- "description": "No such function"
- },
- "422": {
- "description": "`limit` is not a positive integer (code validation)"
- }
- }
- }
- },
- "/api/v1/settings": {
- "get": {
- "summary": "Get current settings (admin only); openai_api_key is masked to a boolean openai_api_key_set",
- "operationId": "getSettings",
- "responses": {
- "200": {
- "description": "Settings (with secret masked)",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "openai_api_base": {
- "type": "string"
- },
- "openai_api_key_set": {
- "type": "boolean"
- },
- "default_embedding_model": {
- "type": "string"
- },
- "cors_origins": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "session_ttl_minutes": {
- "type": "integer"
- },
- "webui_enabled": {
- "type": "boolean"
- },
- "default_project": {
- "type": "string"
- },
- "embedding_connect_timeout_sec": {
- "type": "integer"
- },
- "embedding_read_timeout_sec": {
- "type": "integer"
- },
- "embedding_cache_size": {
- "type": "integer"
- },
- "embedding_cache_ttl_sec": {
- "type": "integer"
- },
- "embedding_cache_max_bytes": {
- "type": "integer"
- },
- "embedding_cache_normalize": {
- "type": "boolean"
- },
- "embedding_client_pool_size": {
- "type": "integer"
- },
- "captcha_provider": {
- "type": "string"
- },
- "captcha_secret_set": {
- "type": "boolean",
- "description": "True when a captcha_secret is configured (the secret itself is never returned)"
- },
- "captcha_verify_url": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- },
- "put": {
- "summary": "Update settings (admin only); omit openai_api_key to keep the existing secret",
- "operationId": "updateSettings",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "openai_api_base": {
- "type": "string"
- },
- "openai_api_key": {
- "type": "string",
- "description": "Omit or pass empty string to preserve the existing key"
- },
- "default_embedding_model": {
- "type": "string"
- },
- "cors_origins": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "session_ttl_minutes": {
- "type": "integer",
- "minimum": 1
- },
- "webui_enabled": {
- "type": "boolean"
- },
- "default_project": {
- "type": "string"
- },
- "embedding_connect_timeout_sec": {
- "type": "integer",
- "minimum": 1,
- "description": "Embedding HTTP connect timeout in seconds (default 10)"
- },
- "embedding_read_timeout_sec": {
- "type": "integer",
- "minimum": 1,
- "description": "Embedding HTTP read timeout in seconds (default 60)"
- },
- "embedding_cache_size": {
- "type": "integer",
- "minimum": 0,
- "description": "Maximum number of cached embedding entries (default 4096)"
- },
- "embedding_cache_ttl_sec": {
- "type": "integer",
- "minimum": 0,
- "description": "Cache entry TTL in seconds; 0 = no expiry (default 86400)"
- },
- "embedding_cache_max_bytes": {
- "type": "integer",
- "minimum": 0,
- "description": "Maximum total bytes of cached vectors (default 268435456 = 256 MB)"
- },
- "embedding_cache_normalize": {
- "type": "boolean",
- "description": "When true, text is trimmed and lower-cased before cache lookup (default false)"
- },
- "embedding_client_pool_size": {
- "type": "integer",
- "minimum": 1,
- "description": "Number of keep-alive HTTP clients pooled per upstream origin (default 4)"
- },
- "captcha_provider": {
- "type": "string",
- "description": "CAPTCHA provider: empty string to disable, 'turnstile', or 'hcaptcha'"
- },
- "captcha_secret": {
- "type": "string",
- "description": "CAPTCHA server-side secret. Omit or pass empty string to preserve the existing secret."
- },
- "captcha_verify_url": {
- "type": "string",
- "description": "Full URL of the CAPTCHA verify endpoint (e.g. https://challenges.cloudflare.com/turnstile/v0/siteverify)"
- }
- }
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Settings updated",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "ok": {
- "type": "boolean"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- }
- },
- "/api/v1/stats": {
- "get": {
- "summary": "Server-wide stats (admin only)",
- "operationId": "globalStats",
- "responses": {
- "200": {
- "description": "Global stats",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "total_collections": {
- "type": "integer"
- },
- "total_documents": {
- "type": "integer"
- },
- "memory_used_bytes": {
- "type": "integer"
- },
- "memory_pressure_percent": {
- "type": "number"
- },
- "insert_count": {
- "type": "integer"
- },
- "query_count": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- }
- },
- "/api/v1/admin/readonly": {
- "get": {
- "summary": "Get the server-wide read-only lock status (admin only)",
- "description": "Server-global, not per project: a single lock state applies to the entire database backing every project. Reflects the database's own authoritative state, obtained live from it on every call - the database can also enter read-only by itself after a degraded or failed recovery, not only via an operator's PUT to this endpoint, so readonly:true does not necessarily mean an operator locked it. While locked, the database refuses writes (observed error: \"Insert rejected: database is in read-only mode. manually locked via SetReadOnly RPC\") and vectorapi surfaces that as HTTP 503.",
- "operationId": "getReadOnly",
- "responses": {
- "200": {
- "description": "Read-only status",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "readonly": {
- "type": "boolean"
- },
- "scope": {
- "type": "string",
- "enum": [
- "server"
- ],
- "description": "Always \"server\" - the lock is not scoped to a project."
- },
- "reason": {
- "type": "string",
- "description": "DB-defined free text explaining why the database is read-only. Present only when non-empty; its absence does not imply the state was operator-set."
- }
- },
- "required": [
- "readonly",
- "scope"
- ]
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- }
- }
- },
- "put": {
- "summary": "Set the server-wide read-only lock (admin only)",
- "description": "Server-global, not per project. Locking blocks writes across every project on this server.",
- "operationId": "setReadOnly",
- "requestBody": {
- "required": true,
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "readonly": {
- "type": "boolean"
- }
- },
- "required": [
- "readonly"
- ]
- }
- }
- }
- },
- "responses": {
- "200": {
- "description": "Read-only status after the change",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "readonly": {
- "type": "boolean"
- },
- "scope": {
- "type": "string",
- "enum": [
- "server"
- ]
- },
- "reason": {
- "type": "string",
- "description": "Present only when non-empty"
- }
- },
- "required": [
- "readonly",
- "scope"
- ]
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Forbidden - admin required"
- },
- "422": {
- "description": "Validation error (readonly missing or not a boolean)"
- },
- "503": {
- "description": "Database rejected the request (e.g. failed to change read-only mode)"
- }
- }
- }
- },
- "/api/v1/projects/{project}/files": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "get": {
- "summary": "List the project's files, newest first",
- "description": "Reads follow the scope rules under the reserved '_files' pseudo-collection. limit is clamped to 1-1000 rather than refused.",
- "parameters": [
- {
- "name": "limit",
- "in": "query",
- "schema": {
- "type": "integer",
- "minimum": 1,
- "maximum": 1000,
- "default": 100
- }
- },
- {
- "name": "offset",
- "in": "query",
- "schema": {
- "type": "integer",
- "minimum": 0
- }
- }
- ],
- "responses": {
- "200": {
- "description": "The files",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "files": {
- "type": "array",
- "items": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "content_type": {
- "type": "string"
- },
- "size": {
- "type": "integer"
- },
- "checksum": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- }
- }
- }
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- },
- "403": {
- "description": "Scope does not grant '_files'"
- }
- }
- }
- },
- "/api/v1/projects/{project}/files/{name}": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string",
- "maxLength": 128,
- "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
- },
- "description": "Letters, digits, '.', '-' and '_'. No leading '.', no '..', no path separator, no ':'."
- }
- ],
- "get": {
- "summary": "Download the file's bytes",
- "description": "Answers with the stored bytes and the stored content type, plus X-File-Checksum and a Content-Disposition naming the file.",
- "responses": {
- "200": {
- "description": "The file content",
- "content": {
- "*/*": {
- "schema": {
- "type": "string",
- "format": "binary"
- }
- }
- }
- },
- "404": {
- "description": "No such file"
- },
- "422": {
- "description": "Unusable file name (with the reason) - never 404, because the name is unusable rather than missing"
- }
- }
- },
- "put": {
- "summary": "Store the raw request body under this name, replacing whatever was there",
- "description": "Requires a full (non-scoped) key with project access: replacing a tenant's asset is a management act. The body is the content - not base64, not a JSON wrapper. Content type comes from the Content-Type header.",
- "requestBody": {
- "required": true,
- "content": {
- "*/*": {
- "schema": {
- "type": "string",
- "format": "binary"
- }
- }
- }
- },
- "responses": {
- "201": {
- "description": "Stored under a new name",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "content_type": {
- "type": "string"
- },
- "size": {
- "type": "integer"
- },
- "checksum": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "200": {
- "description": "Replaced an existing file",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "content_type": {
- "type": "string"
- },
- "size": {
- "type": "integer"
- },
- "checksum": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "403": {
- "description": "Forbidden - scoped keys cannot write files"
- },
- "422": {
- "description": "Empty body, unusable name, or file_too_large"
- }
- }
- },
- "delete": {
- "summary": "Delete the file",
- "description": "Safe against content dedup: identical bytes under two names share storage and are reference-counted, so deleting one name leaves the other readable.",
- "responses": {
- "200": {
- "description": "Deleted"
- },
- "404": {
- "description": "No such file"
- },
- "403": {
- "description": "Forbidden - scoped keys cannot delete files"
- }
- }
- }
- },
- "/api/v1/projects/{project}/files/{name}/info": {
- "parameters": [
- {
- "name": "project",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string"
- }
- },
- {
- "name": "name",
- "in": "path",
- "required": true,
- "schema": {
- "type": "string",
- "maxLength": 128,
- "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]*$"
- },
- "description": "Letters, digits, '.', '-' and '_'. No leading '.', no '..', no path separator, no ':'."
- }
- ],
- "get": {
- "summary": "File metadata without the bytes",
- "responses": {
- "200": {
- "description": "Metadata",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "content_type": {
- "type": "string"
- },
- "size": {
- "type": "integer"
- },
- "checksum": {
- "type": "string"
- },
- "created_at": {
- "type": "integer"
- }
- }
- }
- }
- }
- },
- "404": {
- "description": "No such file"
- }
- }
- }
- },
- "/version": {
- "get": {
- "summary": "The running server's version",
- "description": "Needs no credential - a version string is not a secret, and a client that cannot ask has to probe a behaviour to find out which server it is talking to.",
- "responses": {
- "200": {
- "description": "Version info",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "version": {
- "type": "string"
- },
- "commit": {
- "type": "string"
- },
- "db_client": {
- "type": "string"
- }
- }
- }
- }
- }
- }
- }
- }
- },
- "/api/v1/version": {
- "get": {
- "summary": "The running server's version",
- "description": "Needs any valid key; everything under /api/ is authenticated.",
- "responses": {
- "200": {
- "description": "Version info",
- "content": {
- "application/json": {
- "schema": {
- "type": "object",
- "properties": {
- "name": {
- "type": "string"
- },
- "version": {
- "type": "string"
- },
- "commit": {
- "type": "string"
- },
- "db_client": {
- "type": "string"
- }
- }
- }
- }
- }
- },
- "401": {
- "description": "Unauthorized"
- }
- }
- }
- }
- }
- }
|