|
1 | 1 | """High-level client for Kiket extension endpoints.""" |
2 | 2 | from __future__ import annotations |
3 | 3 |
|
4 | | -from typing import Any |
| 4 | +from typing import Any, TypedDict |
5 | 5 |
|
6 | 6 | from .client import KiketClient |
7 | 7 | from .custom_data import ExtensionCustomDataClient |
8 | 8 | from .secrets import ExtensionSecretManager |
9 | 9 | from .sla import ExtensionSlaEventsClient |
10 | 10 |
|
11 | 11 |
|
| 12 | +class RateLimitInfo(TypedDict): |
| 13 | + """Shape of the `/api/v1/ext/rate_limit` response.""" |
| 14 | + |
| 15 | + limit: int |
| 16 | + remaining: int |
| 17 | + window_seconds: int |
| 18 | + reset_in: int |
| 19 | + |
| 20 | + |
12 | 21 | class ExtensionEndpoints: |
13 | 22 | """Typed helpers for calling common Kiket extension endpoints.""" |
14 | 23 |
|
@@ -55,6 +64,18 @@ def sla_events(self, project_id: int | str) -> ExtensionSlaEventsClient: |
55 | 64 | """Return a helper for querying SLA alerts for a project.""" |
56 | 65 | return ExtensionSlaEventsClient(self._client, project_id) |
57 | 66 |
|
| 67 | + async def rate_limit(self) -> RateLimitInfo: |
| 68 | + """Fetch the current extension-specific rate limit window.""" |
| 69 | + response = await self._client.get("/api/v1/ext/rate_limit") |
| 70 | + payload = response.json() |
| 71 | + data = payload.get("rate_limit") or {} |
| 72 | + return { |
| 73 | + "limit": int(data.get("limit", 0) or 0), |
| 74 | + "remaining": int(data.get("remaining", 0) or 0), |
| 75 | + "window_seconds": int(data.get("window_seconds", 0) or 0), |
| 76 | + "reset_in": int(data.get("reset_in", 0) or 0), |
| 77 | + } |
| 78 | + |
58 | 79 | def _version_headers(self) -> dict[str, str]: |
59 | 80 | if not self._event_version: |
60 | 81 | return {} |
|
0 commit comments