-
Notifications
You must be signed in to change notification settings - Fork 314
feat(usage-api): add toggle to query additional usage, and add pooled usage to /v1/usage
#832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
huzky-v
wants to merge
19
commits into
Soju06:main
Choose a base branch
from
huzky-v:feat/v1-usage-enhance
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
87f8196
feat(usage-api): expose account pool usage sections
Komzpa a15734d
fix(api-keys): keep scoped empty pools empty
Komzpa c1b3690
fix(api-keys): backfill new limit usage
mgwals d514e4a
fix(api-keys): truncate cost backfill per request
mgwals 1868621
fix(api-keys): keep duplicate limit validation repository-free
Komzpa 60ed9e0
fix(api-keys): use bigint for cost backfill
Komzpa 9444472
test(api-keys): cover bigint cost backfill
Komzpa 75a2b9a
docs(openspec): align limit backfill preservation rule
Komzpa 87fa42e
docs(openspec): align main API key usage backfill rule
Komzpa 9e1f6dd
docs(openspec): finish usage sections checklist
Komzpa 0e4da80
fix(api-keys): rebase usage sections migration
Komzpa 8d037d6
feat(api-keys): hide upstream quota for key clients
Komzpa 8897fdc
chore: format proxy api quota headers
Komzpa 30616fb
fix(db): merge api key migration heads
Komzpa 4fca0c2
fix(api-keys): hide upstream pool usage from clients
Komzpa 20f1579
test(api-keys): pin scoped empty pooled credits
Komzpa a7b3dcc
fix(api-keys): merge quota visibility with reauth head
Komzpa b63be74
fix db heads?
huzky-v ddd54e2
fix(db): merge API key quota and dashboard guest heads
Komzpa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
app/db/alembic/versions/20260601_010000_add_api_key_usage_sections.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """add api key usage sections | ||
|
|
||
| Revision ID: 20260601_010000_add_api_key_usage_sections | ||
| Revises: 20260602_060000_merge_account_workspace_and_failure_heads | ||
| Create Date: 2026-06-01 01:00:00.000000 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.engine import Connection | ||
|
|
||
| revision = "20260601_010000_add_api_key_usage_sections" | ||
| down_revision = "20260602_060000_merge_account_workspace_and_failure_heads" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def _table_exists(connection: Connection, table_name: str) -> bool: | ||
| inspector = sa.inspect(connection) | ||
| return inspector.has_table(table_name) | ||
|
|
||
|
|
||
| def _columns(connection: Connection, table_name: str) -> set[str]: | ||
| inspector = sa.inspect(connection) | ||
| if not inspector.has_table(table_name): | ||
| return set() | ||
| return {str(column["name"]) for column in inspector.get_columns(table_name) if column.get("name") is not None} | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| bind = op.get_bind() | ||
| if not _table_exists(bind, "api_keys"): | ||
| return | ||
|
|
||
| existing_columns = _columns(bind, "api_keys") | ||
| with op.batch_alter_table("api_keys") as batch_op: | ||
| if "usage_sections" not in existing_columns: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "usage_sections", | ||
| sa.Text(), | ||
| nullable=False, | ||
| server_default="upstream_limits,account_pool_usage", | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| bind = op.get_bind() | ||
| if not _table_exists(bind, "api_keys"): | ||
| return | ||
|
|
||
| existing_columns = _columns(bind, "api_keys") | ||
| with op.batch_alter_table("api_keys") as batch_op: | ||
| if "usage_sections" in existing_columns: | ||
| batch_op.drop_column("usage_sections") |
50 changes: 50 additions & 0 deletions
50
app/db/alembic/versions/20260608_000000_add_hide_upstream_quota_from_api_keys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """add hide upstream quota from api keys setting | ||
|
|
||
| Revision ID: 20260608_000000_add_hide_upstream_quota_from_api_keys | ||
| Revises: 20260607_000000_merge_weekly_monthly_useragent_heads | ||
| Create Date: 2026-06-08 00:00:00.000000 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from sqlalchemy.engine import Connection | ||
|
|
||
| revision = "20260608_000000_add_hide_upstream_quota_from_api_keys" | ||
| down_revision = "20260607_000000_merge_weekly_monthly_useragent_heads" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def _has_table(connection: Connection, table_name: str) -> bool: | ||
| return sa.inspect(connection).has_table(table_name) | ||
|
|
||
|
|
||
| def _columns(connection: Connection, table_name: str) -> set[str]: | ||
| if not _has_table(connection, table_name): | ||
| return set() | ||
| return {column["name"] for column in sa.inspect(connection).get_columns(table_name)} | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| bind = op.get_bind() | ||
| dashboard_columns = _columns(bind, "dashboard_settings") | ||
| if dashboard_columns and "hide_upstream_quota_from_api_keys" not in dashboard_columns: | ||
| with op.batch_alter_table("dashboard_settings") as batch_op: | ||
| batch_op.add_column( | ||
| sa.Column( | ||
| "hide_upstream_quota_from_api_keys", | ||
| sa.Boolean(), | ||
| server_default=sa.false(), | ||
| nullable=False, | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| bind = op.get_bind() | ||
| dashboard_columns = _columns(bind, "dashboard_settings") | ||
| if dashboard_columns and "hide_upstream_quota_from_api_keys" in dashboard_columns: | ||
| with op.batch_alter_table("dashboard_settings") as batch_op: | ||
| batch_op.drop_column("hide_upstream_quota_from_api_keys") |
25 changes: 25 additions & 0 deletions
25
app/db/alembic/versions/20260608_010000_merge_api_key_usage_and_quota_visibility_heads.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """merge API key usage sections and quota visibility heads | ||
|
|
||
| Revision ID: 20260608_010000_merge_api_key_usage_and_quota_visibility_heads | ||
| Revises: 20260601_010000_add_api_key_usage_sections, | ||
| 20260608_000000_add_hide_upstream_quota_from_api_keys | ||
| Create Date: 2026-06-08 01:00:00.000000 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| revision = "20260608_010000_merge_api_key_usage_and_quota_visibility_heads" | ||
| down_revision = ( | ||
| "20260601_010000_add_api_key_usage_sections", | ||
| "20260608_000000_add_hide_upstream_quota_from_api_keys", | ||
| ) | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| pass | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| pass |
26 changes: 26 additions & 0 deletions
26
app/db/alembic/versions/20260616_000000_merge_api_key_quota_and_dashboard_guest_heads.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| """merge API key quota visibility and dashboard guest heads | ||
|
|
||
| Revision ID: 20260616_000000_merge_api_key_quota_and_dashboard_guest_heads | ||
| Revises: | ||
| - 20260608_010000_merge_api_key_usage_and_quota_visibility_heads | ||
| - 20260611_000000_merge_dashboard_guest_and_weekly_useragent_heads | ||
| Create Date: 2026-06-16 00:00:00.000000 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| revision = "20260616_000000_merge_api_key_quota_and_dashboard_guest_heads" | ||
| down_revision = ( | ||
| "20260608_010000_merge_api_key_usage_and_quota_visibility_heads", | ||
| "20260611_000000_merge_dashboard_guest_and_weekly_useragent_heads", | ||
| ) | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| pass | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.