OpenAI usage tracking: Project ID setting is ignored

Aperta
#1,247 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@dajiaohuang ci sta già lavorando.

Dal 20/10/2026.

  • #1248 di @dajiaohuang — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
php, wordpress
Ambito
api, backend

Direzione di ricerca

Read includes/Classifai/Providers/ProviderProfiles.php and trace CredentialResolver::resolve() for the api_usage_tracking profile; the issue names the affected fields and request path. Check the existing credential resolver and UsageTrackingProvider tests, then verify that configured project IDs appear as project_ids on costs requests and are omitted when unset. A linked pull request is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

The AI Usage Tracking feature lets you enter an optional Project ID so cost data is restricted to a single OpenAI project (see wp-hooks-docs/docs/02.feature-configuration/19.usage-tracking.md: "Optionally enter a Project ID to restrict cost data to a single OpenAI project."). The value is saved, but it never reaches the OpenAI costs request, so the usage and cost totals are always organization-wide.

Steps to reproduce
  1. Enable ClassifAI → Usage Tracking → AI Usage Tracking and select OpenAI.
  2. Enter an Admin API key and a Project ID (e.g. proj_abc123), then save the settings.
  3. Trigger a usage refresh (wait for the Action Scheduler run or click Refresh Usage Data).
  4. Inspect the request to https://api.openai.com/v1/organization/costs: there is no project_ids query arg, so the totals include every project in the organization.
Expected behavior

The saved Project ID should be sent as the project_ids query arg on the costs request, which is what UsageTrackingProvider::fetch_period() attempts to do.

Root cause

UsageTrackingProvider::fetch_period() reads the setting with get_credential( 'project_id', $settings ). That call goes through Provider::get_credentials() → CredentialResolver::resolve(), which keeps only the fields listed in the provider profile's credential_fields. The api_usage_tracking profile in includes/Classifai/Providers/ProviderProfiles.php lists only api_key and authenticated, so project_id is filtered out and $project_id is always empty. That makes the if ( ! empty( $project_id ) ) { $url = add_query_arg( 'project_ids', $project_id, $url ); } branch unreachable.

This is the same pattern the Azure profiles already use: the non-secret deployment value is listed next to the credentials so it survives resolution.

Proposed fix

Add project_id to the api_usage_tracking profile's credential_fields (it stays out of sensitive_fields, so it is not obfuscated) and add regression tests that cover:

  • CredentialResolver::resolve( 'openai_usage_tracking', ... ) keeps project_id;
  • fetch_period() requests include project_ids=<value> when a Project ID is configured, and omit it when not.

A PR covering this will follow.

Lingua principale
PHP
Stelle
714
Fork
68
Merge medio
4h 32m
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di 10up/classifai

Tutte le issue di 10up/classifai

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.