Skip to content

Async fetch_related_object_async / fetch_event_async send "usage" as an API parameter #1948

Open

Description

@sebxt

What happens

StripeClient.raw_request_async does not remove the internal usage keyword from params the way raw_request does. The SDK's own event notification helpers pass usage=[...] to it, so every async fetch adds usage[0]=... to the request.

For a related object with a v1 URL the API rejects the request as an unknown parameter. Against stripe-mock:

sync:  Meter
async error: InvalidRequestError Request req_123: Request validation error: ... additional properties are not allowed

Request URLs observed with a stub HTTP client for the same notification:

sync  get https://api.stripe.com/v1/accounts/acct_123
async get https://api.stripe.com/v1/accounts/acct_123?usage[0]=fetch_related_object

fetch_event_async() has the same problem (/v2/core/events/evt_...?usage[0]=pushed_event_pull&usage[1]=pushed_event_pull_async). The request telemetry also reports ["raw_request", "async"] instead of the usage the caller passed.

What should happen

The async path should behave like the sync path: usage is consumed as telemetry and never sent to the API.

Minimal repro

import asyncio, json, stripe

client = stripe.StripeClient("sk_test_123", base_addresses={"api": "http://localhost:12111"})  # stripe-mock
payload = json.dumps({
    "id": "evt_1", "object": "v2.core.event",
    "type": "v1.billing.meter.error_report_triggered",
    "created": "2024-01-01T00:00:00Z", "livemode": False,
    "related_object": {"id": "mtr_123", "type": "billing.meter", "url": "/v1/billing/meters/mtr_123"},
})
notif = client.parse_event_notification_without_verification(payload)
notif.fetch_related_object()                        # works
asyncio.run(notif.fetch_related_object_async())     # InvalidRequestError

Root cause

In stripe/_stripe_client.py, raw_request does usage = params.pop("usage", ["raw_request"]), but raw_request_async hardcodes usage=["raw_request"] and leaves usage inside params, which are then encoded into the query string (GET) or body (POST).

Tested on master at aff846c (16.0.0).

Activity

  1. Sahas2711 commented on Nov 1, 2026

    @Sahas2711

    Hi @sebxt,

    I've implemented a fix for this issue in my fork.

    The change extracts the internal usage parameter using params.pop("usage", ["raw_request"]) in raw_request_async() and passes the extracted value to the requestor, matching synchronous behavior.

    I've pushed the changes and verified that my branch is mergeable.

    However, GitHub currently restricts opening pull requests to repository collaborators, so I'm unable to submit the PR.

    Would a maintainer be able to enable external PR submissions or help review my proposed fix?

    Fork: https://github.com/Sahas2711/stripe-python
    Branch: fix/async-usage-parameter-1948

    Thanks!

  2. jar-stripe commented on Nov 2, 2026

    @jar-stripe
    Contributor

    Hi @sebxt apologies for the delay! Will take a look ASAP!

    @Sahas2711 Thank you for taking a look at this, but at this time we are unable to accept contributions from the community. Sorry about that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions