{"openapi":"3.0.3","info":{"title":"AISearchStackHub Partner API","description":"Every partner operation requires an HTTP Authorization header in the form Bearer <partner-token>. The Bearer scheme name is case-insensitive, and the parsed credential must be one non-whitespace value. Authentication succeeds only when token lookup resolves to an active, unrevoked token whose expiry is in the future or null. The partner_ prefix is generated by the provisioner; it is not a separate authentication method or a prefix-based check. The API reads no query-string token, cookie, Basic credential, or alternate API-key header. The partner API has no version selector: endpoints use unversioned `/api/partner/...` paths, and no path, header, or query parameter selects an API version. OpenAPI `info.version: 1.0.0` identifies this specification document; it does not version or negotiate these request URLs and is not a backward-compatibility guarantee. No general backward-compatibility window or deprecation or sunset schedule is documented or promised. Authenticated endpoints provide partner-scoped brand visibility data. The production rate limit is 60 requests per 60-second window per authenticated token ID, shared by all three partner GET operations within a Node process; this is a fixed-window limit. The window starts when the first request for that token reaches the limiter and expires 60 seconds after that start; later requests do not move the reset time. Only authenticated requests reach the limiter, and scoped visibility routes validate the UUID first. After authentication, the limiter counts requests before brand-scope and history-filter checks, so a valid-UUID request can consume quota before returning 403 or a history-filter 400. An over-limit request returns 429 before the route handler runs. The bucket is process-local and in-memory, not deployment-wide or IP-based; separate processes or instances can have separate buckets, and a process restart clears its bucket. Requests over the allowance return 429 Too Many Requests with matching runtime-calculated Retry-After and error.retry_after values for the seconds until the current window expires. No remaining-quota, absolute-reset, or X-RateLimit-* headers, separate reset timestamp, or reset endpoint are provided.","version":"1.0.0"},"servers":[{"url":"https://aisearchstackhub.ai","description":"AISearchStackHub"}],"security":[{"PartnerBearerAuth":[]}],"paths":{"/api/partner/brands":{"get":{"operationId":"listAccessibleBrands","summary":"List accessible brands","description":"Returns the full collection of brands explicitly scoped to the authenticated partner token as { brands: [...] }, ordered by brand_id ascending. For each latest_visibility_at, the selected visibility_weekly report is ranked by score_week descending, then score_timestamp descending; the implementation defines no further report tie-break when both values match. This endpoint has no supported pagination parameters or pagination metadata.","security":[{"PartnerBearerAuth":[]}],"responses":{"200":{"description":"Accessible brands, or an empty collection when the token has no brand scope.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BrandCollection"},"examples":{"BrandCollectionSuccess":{"$ref":"#/components/examples/BrandCollectionSuccess"}}}}},"401":{"description":"A missing or unparsable Bearer header returns partner_token_required. A parsed token that is unknown, inactive, revoked, expired, or otherwise unusable returns partner_token_invalid; token lookup failures use the same partner_token_invalid response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"PartnerTokenRequired":{"$ref":"#/components/examples/PartnerTokenRequired"},"PartnerTokenInvalid":{"$ref":"#/components/examples/PartnerTokenInvalid"}}}}},"429":{"description":"The process-local 60-request/60-second partner API rate limit uses one bucket per authenticated token ID, shared by all three partner GET operations within a Node process. The fixed window starts when the first request for that token reaches the limiter and expires 60 seconds after that start; later requests do not move the reset time. Only requests passing authentication reach the limiter, and scoped visibility routes validate the UUID before authentication. The limiter counts requests before brand-scope and history-filter checks, so a valid-UUID request can use quota before returning 403 or a history-filter 400. An over-limit request returns 429 before the route handler runs. The bucket is in-memory and not deployment-wide or IP-based; separate processes or instances can have separate buckets, and restarting a process clears its bucket. The response includes the runtime-calculated seconds until the current window expires in both the Retry-After header and error.retry_after; no remaining-quota, absolute-reset, or X-RateLimit-* headers, separate reset timestamp, or reset endpoint are provided.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiRateLimitError"},"examples":{"RateLimited":{"$ref":"#/components/examples/RateLimited"}}}},"headers":{"Retry-After":{"$ref":"#/components/headers/RetryAfter"}}},"500":{"description":"The server could not list accessible brands.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"ListBrandsInternalError":{"$ref":"#/components/examples/ListBrandsInternalError"}}}}}}}},"/api/partner/brands/{brandId}/visibility":{"get":{"operationId":"getLatestVisibility","summary":"Get the latest visibility score","description":"Returns one object for the latest completed visibility_weekly report for an authorized brand, ranked by score_week descending, then score_timestamp descending. The implementation defines no further report tie-break when both values match. The brandId UUID is validated before authentication, so an invalid UUID can return 400 before 401. No pagination parameters or pagination metadata are provided.","security":[{"PartnerBearerAuth":[]}],"parameters":[{"$ref":"#/components/parameters/BrandId"}],"responses":{"200":{"description":"One latest completed visibility report object.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VisibilityReport"},"examples":{"VisibilityReportSuccess":{"$ref":"#/components/examples/VisibilityReportSuccess"}}}}},"400":{"description":"The brandId path parameter is not a UUID. This check runs before authentication, so it can return 400 before 401.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"InvalidBrandId":{"$ref":"#/components/examples/InvalidBrandId"}}}}},"401":{"description":"A missing or unparsable Bearer header returns partner_token_required. A parsed token that is unknown, inactive, revoked, expired, or otherwise unusable returns partner_token_invalid; token lookup failures use the same partner_token_invalid response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"PartnerTokenRequired":{"$ref":"#/components/examples/PartnerTokenRequired"},"PartnerTokenInvalid":{"$ref":"#/components/examples/PartnerTokenInvalid"}}}}},"403":{"description":"The partner token is not scoped to this brand.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"BrandAccessDenied":{"$ref":"#/components/examples/BrandAccessDenied"}}}}},"404":{"description":"No completed weekly visibility report exists for this brand.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"VisibilityNotFound":{"$ref":"#/components/examples/VisibilityNotFound"}}}}},"429":{"description":"The process-local 60-request/60-second partner API rate limit uses one bucket per authenticated token ID, shared by all three partner GET operations within a Node process. The fixed window starts when the first request for that token reaches the limiter and expires 60 seconds after that start; later requests do not move the reset time. Only requests passing authentication reach the limiter, and scoped visibility routes validate the UUID before authentication. The limiter counts requests before brand-scope and history-filter checks, so a valid-UUID request can use quota before returning 403 or a history-filter 400. An over-limit request returns 429 before the route handler runs. The bucket is in-memory and not deployment-wide or IP-based; separate processes or instances can have separate buckets, and restarting a process clears its bucket. The response includes the runtime-calculated seconds until the current window expires in both the Retry-After header and error.retry_after; no remaining-quota, absolute-reset, or X-RateLimit-* headers, separate reset timestamp, or reset endpoint are provided.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiRateLimitError"},"examples":{"RateLimited":{"$ref":"#/components/examples/RateLimited"}}}},"headers":{"Retry-After":{"$ref":"#/components/headers/RetryAfter"}}},"500":{"description":"The server could not fetch visibility data.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"VisibilityInternalError":{"$ref":"#/components/examples/VisibilityInternalError"}}}}}}}},"/api/partner/brands/{brandId}/visibility/history":{"get":{"operationId":"getVisibilityHistory","summary":"Get historical visibility scores","description":"Returns matching completed visibility_weekly reports as a direct JSON array, ordered by score_week descending, then score_timestamp descending, then report id descending. The id is used only as a tie-break and is not returned. The brandId UUID is validated before authentication. For a valid UUID, authentication and rate limiting run before brand scope, and brand scope is checked before the from, to, and limit filters; an earlier 401, 429, or 403 can therefore precede a filter-validation 400. The inclusive from and to filters apply to report weeks (score_week) and must be valid YYYY-MM-DD calendar dates with from on or before to. limit is a maximum result count, not a page size: it defaults to 12 and must be from 1 through 100. The response has no page, offset, or cursor continuation, total count, or next-page metadata. An array at the limit does not reveal whether more reports match inside that date window. To retrieve older history, split the range into non-overlapping date windows small enough to fit the cap and combine the arrays.","security":[{"PartnerBearerAuth":[]}],"parameters":[{"$ref":"#/components/parameters/BrandId"},{"name":"from","in":"query","required":false,"description":"Inclusive lower bound on the report week (score_week). Must be a valid calendar date in YYYY-MM-DD format; when to is also supplied, from must be on or before it.","schema":{"type":"string","format":"date","pattern":"^\\d{4}-\\d{2}-\\d{2}$"}},{"name":"to","in":"query","required":false,"description":"Inclusive upper bound on the report week (score_week). Must be a valid calendar date in YYYY-MM-DD format; when from is also supplied, it must be on or before to.","schema":{"type":"string","format":"date","pattern":"^\\d{4}-\\d{2}-\\d{2}$"}},{"name":"limit","in":"query","required":false,"description":"Maximum number of reports returned, not a page size. Defaults to 12 and must be from 1 through 100. Reaching this cap does not indicate whether more matches exist, and no continuation mechanism is provided.","schema":{"type":"integer","format":"int32","minimum":1,"maximum":100,"default":12}}],"responses":{"200":{"description":"Historical visibility reports, or an empty array when no reports match.","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/VisibilityReport"}},"examples":{"VisibilityHistorySuccess":{"$ref":"#/components/examples/VisibilityHistorySuccess"}}}}},"400":{"description":"The brandId path parameter is not a UUID, or a history filter failed validation. brandId is checked before authentication; filters are checked after authentication, rate limiting, and brand scope.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"InvalidBrandId":{"$ref":"#/components/examples/InvalidBrandId"},"InvalidFromDate":{"$ref":"#/components/examples/InvalidFromDate"},"InvalidToDate":{"$ref":"#/components/examples/InvalidToDate"},"InvalidDateRange":{"$ref":"#/components/examples/InvalidDateRange"},"InvalidLimit":{"$ref":"#/components/examples/InvalidLimit"}}}}},"401":{"description":"A missing or unparsable Bearer header returns partner_token_required. A parsed token that is unknown, inactive, revoked, expired, or otherwise unusable returns partner_token_invalid; token lookup failures use the same partner_token_invalid response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"PartnerTokenRequired":{"$ref":"#/components/examples/PartnerTokenRequired"},"PartnerTokenInvalid":{"$ref":"#/components/examples/PartnerTokenInvalid"}}}}},"403":{"description":"The partner token is not scoped to this brand.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"BrandAccessDenied":{"$ref":"#/components/examples/BrandAccessDenied"}}}}},"429":{"description":"The process-local 60-request/60-second partner API rate limit uses one bucket per authenticated token ID, shared by all three partner GET operations within a Node process. The fixed window starts when the first request for that token reaches the limiter and expires 60 seconds after that start; later requests do not move the reset time. Only requests passing authentication reach the limiter, and scoped visibility routes validate the UUID before authentication. The limiter counts requests before brand-scope and history-filter checks, so a valid-UUID request can use quota before returning 403 or a history-filter 400. An over-limit request returns 429 before the route handler runs. The bucket is in-memory and not deployment-wide or IP-based; separate processes or instances can have separate buckets, and restarting a process clears its bucket. The response includes the runtime-calculated seconds until the current window expires in both the Retry-After header and error.retry_after; no remaining-quota, absolute-reset, or X-RateLimit-* headers, separate reset timestamp, or reset endpoint are provided.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiRateLimitError"},"examples":{"RateLimited":{"$ref":"#/components/examples/RateLimited"}}}},"headers":{"Retry-After":{"$ref":"#/components/headers/RetryAfter"}}},"500":{"description":"The server could not fetch visibility history.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PartnerApiError"},"examples":{"HistoryInternalError":{"$ref":"#/components/examples/HistoryInternalError"}}}}}}}}},"components":{"securitySchemes":{"PartnerBearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"partner-token","description":"Every partner operation requires an HTTP Authorization header in the form Bearer <partner-token>. The Bearer scheme name is case-insensitive, and the parsed credential must be one non-whitespace value. Authentication succeeds only when token lookup resolves to an active, unrevoked token whose expiry is in the future or null. The partner_ prefix is generated by the provisioner; it is not a separate authentication method or a prefix-based check. Query-string tokens, cookies, Basic authentication, and alternate API-key headers are not accepted."}},"parameters":{"BrandId":{"name":"brandId","in":"path","required":true,"description":"UUID of the authorized brand.","schema":{"type":"string","format":"uuid"}}},"headers":{"RetryAfter":{"description":"Runtime-calculated number of seconds until the current fixed window expires. This header is emitted on throttled responses; the value is not an absolute reset timestamp.","schema":{"type":"integer","minimum":1}}},"schemas":{"PartnerApiError":{"type":"object","description":"Non-429 error responses have the exact shape { \"error\": { \"code\": \"...\", \"message\": \"...\" } }. The error object contains only code and message.","required":["error"],"additionalProperties":false,"properties":{"error":{"type":"object","required":["code","message"],"additionalProperties":false,"properties":{"code":{"type":"string"},"message":{"type":"string"}}}}},"PartnerApiRateLimitError":{"type":"object","description":"The exact error body for 429 responses: { \"error\": { \"code\": \"...\", \"message\": \"...\", \"retry_after\": 1 } }. The retry_after value is runtime-calculated.","required":["error"],"additionalProperties":false,"properties":{"error":{"type":"object","required":["code","message","retry_after"],"additionalProperties":false,"properties":{"code":{"type":"string"},"message":{"type":"string"},"retry_after":{"type":"integer","minimum":1,"description":"Runtime-calculated number of seconds until the current fixed window expires."}}}}},"BrandCollection":{"type":"object","required":["brands"],"properties":{"brands":{"type":"array","description":"Brands explicitly scoped to the partner token.","items":{"$ref":"#/components/schemas/Brand"}}}},"Brand":{"type":"object","required":["brand_id","name","monitoring_enabled","latest_visibility_at"],"properties":{"brand_id":{"type":"string","format":"uuid"},"name":{"type":"string","nullable":true},"monitoring_enabled":{"type":"boolean"},"latest_visibility_at":{"type":"string","format":"date-time","nullable":true}}},"VisibilityReport":{"type":"object","required":["brand_id","visibility_score","score_timestamp","score_week","engine_breakdown"],"properties":{"brand_id":{"type":"string","format":"uuid"},"visibility_score":{"type":"integer","minimum":0,"maximum":100},"score_timestamp":{"type":"string","format":"date-time"},"score_week":{"type":"string","format":"date"},"engine_breakdown":{"type":"object","description":"Visibility data keyed by engine name.","additionalProperties":{"$ref":"#/components/schemas/EngineBreakdown"}}}},"EngineBreakdown":{"type":"object","required":["visibility_pct","position_avg","share"],"properties":{"visibility_pct":{"type":"integer","minimum":0,"maximum":100},"position_avg":{"type":"integer","nullable":true},"share":{"type":"object","description":"Rounded competitor-domain share percentages keyed by domain.","additionalProperties":{"type":"number","minimum":0,"maximum":100}}}}},"examples":{"BrandCollectionSuccess":{"value":{"brands":[{"brand_id":"123e4567-e89b-12d3-a456-426614174000","name":"Example Brand","monitoring_enabled":true,"latest_visibility_at":"2026-09-01T09:30:00.000Z"}]}},"VisibilityReportSuccess":{"value":{"brand_id":"123e4567-e89b-12d3-a456-426614174000","visibility_score":74,"score_timestamp":"2026-09-01T09:30:00.000Z","score_week":"2026-08-31","engine_breakdown":{"ChatGPT":{"visibility_pct":80,"position_avg":2,"share":{"rival.example":20}},"Claude":{"visibility_pct":70,"position_avg":3,"share":{}},"Perplexity":{"visibility_pct":75,"position_avg":2,"share":{}},"Gemini":{"visibility_pct":71,"position_avg":4,"share":{}}}}},"VisibilityHistorySuccess":{"value":[{"brand_id":"987e6543-e21b-4d3c-8a76-543210fedcba","visibility_score":68,"score_timestamp":"2026-08-25T11:15:00.000Z","score_week":"2026-08-24","engine_breakdown":{"ChatGPT":{"visibility_pct":68,"position_avg":3,"share":{}}}}]},"InvalidBrandId":{"value":{"error":{"code":"invalid_brand_id","message":"brandId must be a UUID"}}},"InvalidFromDate":{"value":{"error":{"code":"invalid_from_date","message":"from must be a valid YYYY-MM-DD date"}}},"InvalidToDate":{"value":{"error":{"code":"invalid_to_date","message":"to must be a valid YYYY-MM-DD date"}}},"InvalidDateRange":{"value":{"error":{"code":"invalid_date_range","message":"from must be on or before to"}}},"InvalidLimit":{"value":{"error":{"code":"invalid_limit","message":"limit must be an integer between 1 and 100"}}},"PartnerTokenRequired":{"value":{"error":{"code":"partner_token_required","message":"Authorization Bearer token required"}}},"PartnerTokenInvalid":{"value":{"error":{"code":"partner_token_invalid","message":"Partner token is invalid"}}},"BrandAccessDenied":{"value":{"error":{"code":"brand_access_denied","message":"Partner token cannot access this brand"}}},"VisibilityNotFound":{"value":{"error":{"code":"visibility_not_found","message":"No completed weekly visibility report found"}}},"RateLimited":{"summary":"Illustrative 429 response; retry_after varies at runtime.","description":"The value 12 is illustrative only. The actual Retry-After header and error.retry_after value are calculated at runtime from the seconds remaining in the current fixed window.","value":{"error":{"code":"rate_limited","message":"Too many partner API requests","retry_after":12}}},"ListBrandsInternalError":{"value":{"error":{"code":"internal_error","message":"Unable to list accessible brands"}}},"VisibilityInternalError":{"value":{"error":{"code":"internal_error","message":"Unable to fetch visibility data"}}},"HistoryInternalError":{"value":{"error":{"code":"internal_error","message":"Unable to fetch visibility history"}}}}}}