Skip to content

feat(seer): Add Seer credit check helper and endpoint - #129130

Merged
srest2021 merged 12 commits into
masterfrom
srest2021/CW-2323
Nov 2, 2026
Merged

srest2021 merged 12 commits into
masterfrom
srest2021/CW-2323

Conversation

@srest2021

@srest2021 srest2021 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes CW-2320
Relates to CW-2323

Adds a backend credit check helper & endpoint for token-billed Seer, so the UI & other entrypoints can tell whether an org can afford an operation before triggering it.

  • can_run_seer_operation(organization, operation) in sentry/seer/credits.py asks billing via a new quotas.backend.check_seer_credits(CheckSeerCreditsRequest) -> CheckSeerCreditsResponse.
  • Each operation maps to the Seer feature billing keys off (autofix / explorer) and a credit estimate. For now every estimate is a placeholder of 100 credits until we figure out better estimates.
  • Gated by the new organizations:seer-credit-checks flag; otherwise always True. Whether the org is token-billed is left to getsentry's quotas implementation.
  • GET /organizations/{org}/seer/credit-check/?operation=autofix_root_cause returns {"hasEnoughCredits": bool}.

via sofia.

--

View Session [Sentry]

Add a helper that asks billing whether an org has enough Seer credits
for an operation, using placeholder per-operation estimates, and an
endpoint the UI can call before triggering one. Gated by
organizations:seer-credit-checks and token-billed-seer-enabled.

Refs CW-2323
@linear-code

linear-code Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

CW-2323

CW-2320

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 28, 2026
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 28, 2026
Comment on lines +22 to +23
AUTOFIX = "autofix"
EXPLORER = "explorer"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using DATA_CATEGORY_BILLABLE_SEER_CREDITS features as a reference

@dataclass(frozen=True)
class SeerOperationConfig:
feature: SeerFeature
estimate: Callable[[], int]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extendable for when we want to dynamically calculate these

Comment thread src/sentry/seer/credits.py Resolved
Rename the helper to can_run_seer_operation so it no longer shares a name
with quotas.backend.has_seer_credits, and the response field to
hasEnoughCredits. Drop the token-billed-seer-enabled check, which belongs
in getsentry's quotas implementation.

Refs CW-2323
Comment thread src/sentry/quotas/base.py Resolved
quotas.backend.has_seer_credits now takes a HasSeerCreditsRequest and
returns a HasSeerCreditsResponse, so getsentry can share it with the
LLM proxy's lease_llm_quota RPC. take_lease is false until leases exist.

Refs CW-2323
@srest2021
srest2021 marked this pull request as ready for review October 29, 2026 21:30
@srest2021
srest2021 requested review from a team as code owners October 29, 2026 21:30
@srest2021
srest2021 requested review from sehr-m and volokluev and removed request for a team October 29, 2026 21:30

def can_run_seer_operation(organization: Organization, operation: SeerOperation) -> bool:
"""Whether the organization has enough Seer credits to run the operation."""
if not features.has("organizations:seer-credit-checks", organization):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not check the token-based billing flag here since I assume quotas.backend.check_seer_credits will do that anyway.

# Conflicts:
#	static/app/utils/api/knownSentryApiUrls.generated.ts

Co-Authored-By: Sofia Rest <[email protected]>
Match the open_pr step value the frontend sends to the autofix endpoint.

Co-Authored-By: Sofia Rest <[email protected]>
@srest2021
srest2021 merged commit 6b9894e into master Nov 2, 2026
99 checks passed
@srest2021
srest2021 deleted the srest2021/CW-2323 branch November 2, 2026 21:53
volokluev added a commit that referenced this pull request Nov 2, 2026
Seer credit checks go through `quotas.backend.check_seer_credits` (added
in #129130). That means getsentry has to implement them in
`getsentry/quotas.py`, which is already overloaded ([review
comment](getsentry/getsentry#22885 (comment))).

This PR adds a dedicated swappable backend, `SENTRY_SEER_CREDIT`, built
the same way as `SENTRY_PARTNERSHIPS`:

- `sentry.seer_credit.SeerCredit` is the default. Every check passes,
which matches the current `Quota.check_seer_credits` default.
- `can_run_seer_operation` now calls
`seer_credit.backend.check_seer_credits`.
- `Quota.check_seer_credits` is removed.

No user-facing change: credit checks are still behind
`organizations:seer-credit-checks`, and every backend involved returns
`has_enough_credits=True`.

**Follow-up:** getsentry/getsentry#22888 implements the backend in
`getsentry/seer_credit.py` and sets `SENTRY_SEER_CREDIT`. Merge this PR
first, then that one. In the gap, getsentry's
`SubscriptionQuota.check_seer_credits` (from getsentry#22885) is no
longer called, so the Seer wallet balance-lookup sample pauses until
#22888 lands.

<!-- junior-request-attribution:start -->
via **volo**.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:slack%3AD0BNNTBGH53%3A1793659141.093839 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/slack%3AD0BNNTBGH53%3A1793659141.093839)
[[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0BNNTBGH53%3A1793659141.093839/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: Volo Kluev <[email protected]>
billyvg added a commit that referenced this pull request Nov 5, 2026
Adds `useSeerCreditCheck(operation)`, which asks `GET
/organizations/{org}/seer/credit-check/?operation=…` whether the org can
afford one Seer operation (an autofix step or a chat message) and
returns `hasEnoughCredits`. Nothing uses it yet; the gating PRs stacked
on this one do.

- It only calls the endpoint for orgs with `seer-credit-checks`. Without
the flag, when disabled, or when the request fails, it returns
`hasEnoughCredits: true`, so a broken check never blocks Seer and the
backend still has the final say.
- `isPending` is only true while a check is in flight (a disabled
TanStack query reports pending forever), so callers can show a
placeholder instead of flashing the start button.
- It is deliberately separate from `useOrganizationSeerSetup`:
setup-check is mounted on many pages that should not make a billing
call, so this one should only be mounted where a Seer trigger is about
to show.
- `staleTime: 0` because credits change outside the page (a run
elsewhere spends them, a billing member tops up in another tab), so the
check reruns on mount and window focus.

The endpoint landed in #129130.

Fixes CW-2327

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants