This PR adds a migration to drop the `subscription_usages` and
`subscription_usage_meters` tables from the database.
We're now using `subscription_usages_v2` and
`subscription_usage_meters_v2` everywhere.
Release Notes:
- N/A
This PR adds two new tables:
- `subscription_usages_v2`
- `subscription_usage_meters_v2`
These are the same as the old ones, except using UUIDs as primary keys.
Release Notes:
- N/A
This PR adds a new `subscription_usage_meters` table to the LLM
database.
We'll use this to track usage of individual models over the number of
requests built-in to the plan.
Release Notes:
- N/A
This PR adds a `plan` column to the `subscription_usages` table.
These tables don't have any records in them yet, so it's fine to make
the column required without a default.
Release Notes:
- N/A
This PR adds a new `subscription_usages` table to the LLM database.
We'll use this table to track usage by subscribers.
Records will be looked up using `(user_id, period_start_at,
period_end_at)` to find the record for a user's current subscription
period.
Release Notes:
- N/A
This PR adds new granular tokens per minute columns to the `models`
table in preparation for more fine-grained rate limits.
The following columns have been added:
- `max_input_tokens_per_minute`
- `max_output_tokens_per_minute`
These mirror the "Maximum input tokens per minute (ITPM)" and "Maximum
output tokens per minute (OTPM)" [rate limits from
Anthropic](https://docs.anthropic.com/en/api/rate-limits#rate-limits).
Release Notes:
- N/A
This PR adds usage-based billing for LLM interactions in the Assistant.
Release Notes:
- N/A
---------
Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Richard <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
This PR reworks our existing billing code in preparation for charging
based on LLM usage.
We aren't yet exercising the new billing-related code outside of
development.
There are some noteworthy changes for our existing LLM usage tracking:
- A new `monthly_usages` table has been added for tracking usage
per-user, per-model, per-month
- The per-month usage measures have been removed, in favor of the
`monthly_usages` table
- All of the per-month metrics in the Clickhouse rows have been changed
from a rolling 30-day window to a calendar month
Release Notes:
- N/A
---------
Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Richard <richard@zed.dev>
Co-authored-by: Max <max@zed.dev>
This PR drops the `cache_creation_input_tokens_this_month ` and
`cache_read_input_tokens_this_month ` columns from the `usages` table in
the LLM database.
We mistakenly added these in #18834, but these aren't necessary due to
the structure of the `usages` table. We weren't actually using these
columns anywhere.
Release Notes:
- N/A
This PR extends the LLM usage tracking to support tracking usage for
cache writes and reads for Anthropic models.
Release Notes:
- N/A
---------
Co-authored-by: Antonio Scandurra <me@as-cii.com>
Co-authored-by: Antonio <antonio@zed.dev>
This PR adds the ability to revoke access tokens for the LLM service.
There is a new `revoked_access_tokens` table that contains the
identifiers (`jti`) of revoked access tokens.
To revoke an access token, insert a record into this table:
```sql
insert into revoked_access_tokens (jti) values ('1e887b9e-37f5-49e8-8feb-3274e5a86b67');
```
We now attach the `jti` as `authn.jti` to the tracing spans so that we
can associate an access token with a given request to the LLM service.
Release Notes:
- N/A
This PR makes it so Zed staff can use a separate Anthropic API key for
the LLM service.
We also added an `is_staff` column to the `usages` table so that we can
exclude staff usage from the "active users" metrics that influence the
rate limits.
Release Notes:
- N/A
---------
Co-authored-by: Max <max@zed.dev>
This PR puts the initial infrastructure for the LLM service's database
in place.
The LLM service will be using a separate Postgres database, with its own
set of migrations.
Currently we only connect to the database in development, as we don't
yet have the database setup for the staging/production environments.
Release Notes:
- N/A