{"openapi":"3.1.0","info":{"title":"pgsenpai API","version":"0.1.0","description":"Start analyses and fetch reports from CI. Authenticate with 'Authorization: Bearer pgs_...'; create tokens under Team → API tokens."},"paths":{"/api/v1/me":{"get":{"tags":["analyses"],"summary":"Who am I","description":"Return the member, organisation, plan and usage behind the token.","operationId":"me_api_v1_me_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MeOut"}}}}}}},"/api/v1/connections":{"get":{"tags":["analyses"],"summary":"Saved connections","description":"List the organisation's saved connections; pass an id to start a run.","operationId":"connections_api_v1_connections_get","responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"items":{"$ref":"#/components/schemas/ConnectionOut"},"type":"array","title":"Response Connections Api V1 Connections Get"}}}}}}},"/api/v1/analyses":{"get":{"tags":["analyses"],"summary":"List analyses","description":"Return the organisation's analyses, newest first.","operationId":"list_analyses_api_v1_analyses_get","parameters":[{"name":"limit","in":"query","required":false,"schema":{"type":"integer","default":50,"title":"Limit"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnalysisOut"},"title":"Response List Analyses Api V1 Analyses Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}},"post":{"tags":["analyses"],"summary":"Start an analysis","description":"Queue an analysis; poll ``GET /analyses/{id}`` until it is done.","operationId":"create_analysis_api_v1_analyses_post","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisCreate"}}}},"responses":{"202":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisStarted"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/analyses/{job_id}":{"get":{"tags":["analyses"],"summary":"One analysis","description":"Return status, summary, comparison with the previous run and files.","operationId":"get_analysis_api_v1_analyses__job_id__get","parameters":[{"name":"job_id","in":"path","required":true,"schema":{"type":"string","title":"Job Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnalysisOut"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/analyses/{job_id}/report":{"get":{"tags":["analyses"],"summary":"The HTML report","description":"Return the report as HTML (404 until the run is done or after expiry).","operationId":"get_report_api_v1_analyses__job_id__report_get","parameters":[{"name":"job_id","in":"path","required":true,"schema":{"type":"string","title":"Job Id"}}],"responses":{"200":{"description":"Successful Response"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/analyses/{job_id}/files/{name}":{"get":{"tags":["analyses"],"summary":"One stored file","description":"Return one of the run's files: report, plan pages, analysis.json, log.","operationId":"get_file_api_v1_analyses__job_id__files__name__get","parameters":[{"name":"job_id","in":"path","required":true,"schema":{"type":"string","title":"Job Id"}},{"name":"name","in":"path","required":true,"schema":{"type":"string","title":"Name"}}],"responses":{"200":{"description":"Successful Response"},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}},"/api/v1/analyses/{job_id}/recommendations":{"get":{"tags":["analyses"],"summary":"Recommendations","description":"Return the rule-based index, rewrite and maintenance findings.","operationId":"get_recommendations_api_v1_analyses__job_id__recommendations_get","parameters":[{"name":"job_id","in":"path","required":true,"schema":{"type":"string","title":"Job Id"}}],"responses":{"200":{"description":"Successful Response","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/FindingOut"},"title":"Response Get Recommendations Api V1 Analyses  Job Id  Recommendations Get"}}}},"422":{"description":"Validation Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/HTTPValidationError"}}}}}}}},"components":{"schemas":{"AnalysisCreate":{"properties":{"connection_string":{"type":"string","maxLength":2000,"title":"Connection String","default":""},"password":{"type":"string","maxLength":500,"title":"Password","default":""},"connection_id":{"anyOf":[{"type":"integer"},{"type":"null"}],"title":"Connection Id"},"title":{"type":"string","maxLength":120,"title":"Title","default":""},"provider":{"type":"string","maxLength":40,"title":"Provider","default":""},"source":{"type":"string","maxLength":60,"title":"Source","default":"pg_stat_statements"},"max_rows":{"anyOf":[{"type":"integer","maximum":100000.0,"minimum":1.0},{"type":"null"}],"title":"Max Rows"},"min_calls":{"anyOf":[{"type":"integer","minimum":0.0},{"type":"null"}],"title":"Min Calls"},"min_avg_ms":{"anyOf":[{"type":"number","minimum":0.0},{"type":"null"}],"title":"Min Avg Ms"},"run_queries":{"type":"boolean","title":"Run Queries","default":true},"statement_timeout_ms":{"anyOf":[{"type":"integer","maximum":86400000.0,"minimum":1000.0},{"type":"null"}],"title":"Statement Timeout Ms"},"explain_timeout":{"anyOf":[{"type":"integer","maximum":86400.0,"minimum":10.0},{"type":"null"}],"title":"Explain Timeout"}},"additionalProperties":false,"type":"object","title":"AnalysisCreate","description":"What a client sends to start an analysis.\n\nGive either ``connection_string`` (with ``password`` unless it is inside\nthe string) or ``connection_id`` of a saved connection."},"AnalysisOut":{"properties":{"id":{"type":"string","title":"Id"},"title":{"type":"string","title":"Title"},"status":{"type":"string","title":"Status"},"target":{"type":"string","title":"Target"},"trigger":{"type":"string","title":"Trigger"},"created_at":{"type":"string","title":"Created At"},"finished_at":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Finished At"},"error":{"type":"string","title":"Error"},"report_ready":{"type":"boolean","title":"Report Ready"},"expired":{"type":"boolean","title":"Expired"},"url":{"type":"string","title":"Url"},"report_url":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Report Url"},"summary":{"additionalProperties":true,"type":"object","title":"Summary"},"comparison":{"anyOf":[{"$ref":"#/components/schemas/ComparisonOut"},{"type":"null"}]},"files":{"items":{"$ref":"#/components/schemas/FileOut"},"type":"array","title":"Files"}},"type":"object","required":["id","title","status","target","trigger","created_at","finished_at","error","report_ready","expired","url","report_url","summary"],"title":"AnalysisOut","description":"One analysis run."},"AnalysisStarted":{"properties":{"id":{"type":"string","title":"Id"},"status":{"type":"string","title":"Status"},"url":{"type":"string","title":"Url"},"notes":{"items":{"type":"string"},"type":"array","title":"Notes"}},"type":"object","required":["id","status","url","notes"],"title":"AnalysisStarted","description":"The reply to a successful start."},"ChangeOut":{"properties":{"query_hash":{"type":"string","title":"Query Hash"},"example":{"type":"string","title":"Example"},"before_ms":{"type":"number","title":"Before Ms"},"after_ms":{"type":"number","title":"After Ms"},"percent":{"type":"integer","title":"Percent"}},"type":"object","required":["query_hash","example","before_ms","after_ms","percent"],"title":"ChangeOut","description":"One statement that got slower, faster or appeared."},"ComparisonOut":{"properties":{"has_previous":{"type":"boolean","title":"Has Previous"},"previous_job":{"anyOf":[{"type":"string"},{"type":"null"}],"title":"Previous Job"},"summary":{"items":{"type":"string"},"type":"array","title":"Summary"},"regressions":{"items":{"$ref":"#/components/schemas/ChangeOut"},"type":"array","title":"Regressions"},"improvements":{"items":{"$ref":"#/components/schemas/ChangeOut"},"type":"array","title":"Improvements"},"new":{"items":{"$ref":"#/components/schemas/ChangeOut"},"type":"array","title":"New"}},"type":"object","required":["has_previous","previous_job","summary","regressions","improvements","new"],"title":"ComparisonOut","description":"How the run compares with the previous run of the same database."},"ConnectionOut":{"properties":{"id":{"type":"integer","title":"Id"},"name":{"type":"string","title":"Name"},"target":{"type":"string","title":"Target"},"provider":{"type":"string","title":"Provider"},"needs_password":{"type":"boolean","title":"Needs Password"}},"type":"object","required":["id","name","target","provider","needs_password"],"title":"ConnectionOut","description":"A saved connection a run can use by id."},"FileOut":{"properties":{"name":{"type":"string","title":"Name"},"size":{"type":"integer","title":"Size"},"url":{"type":"string","title":"Url"}},"type":"object","required":["name","size","url"],"title":"FileOut","description":"One stored file of a run."},"FindingOut":{"properties":{"kind":{"type":"string","title":"Kind"},"title":{"type":"string","title":"Title"},"detail":{"type":"string","title":"Detail"},"sql":{"type":"string","title":"Sql"},"benefit":{"type":"string","title":"Benefit"},"confidence":{"type":"string","title":"Confidence"},"table":{"type":"string","title":"Table"},"query_hash":{"type":"string","title":"Query Hash"}},"type":"object","required":["kind","title","detail","sql","benefit","confidence","table","query_hash"],"title":"FindingOut","description":"One recommendation."},"HTTPValidationError":{"properties":{"detail":{"items":{"$ref":"#/components/schemas/ValidationError"},"type":"array","title":"Detail"}},"type":"object","title":"HTTPValidationError"},"MeOut":{"properties":{"user":{"type":"string","title":"User"},"organisation":{"type":"string","title":"Organisation"},"organisation_id":{"type":"integer","title":"Organisation Id"},"role":{"type":"string","title":"Role"},"plan":{"type":"string","title":"Plan"},"analyses_used":{"type":"integer","title":"Analyses Used"},"analyses_limit":{"type":"integer","title":"Analyses Limit"},"token":{"type":"string","title":"Token"}},"type":"object","required":["user","organisation","organisation_id","role","plan","analyses_used","analyses_limit","token"],"title":"MeOut","description":"Who the token acts as."},"ValidationError":{"properties":{"loc":{"items":{"anyOf":[{"type":"string"},{"type":"integer"}]},"type":"array","title":"Location"},"msg":{"type":"string","title":"Message"},"type":{"type":"string","title":"Error Type"},"input":{"title":"Input"},"ctx":{"type":"object","title":"Context"}},"type":"object","required":["loc","msg","type"],"title":"ValidationError"}},"securitySchemes":{"token":{"type":"http","scheme":"bearer"}}},"security":[{"token":[]}]}