OpenAI usage tracking: Project ID setting is ignored
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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
- Enable ClassifAI → Usage Tracking → AI Usage Tracking and select OpenAI.
- Enter an Admin API key and a Project ID (e.g.
proj_abc123), then save the settings. - Trigger a usage refresh (wait for the Action Scheduler run or click Refresh Usage Data).
- Inspect the request to
https://api.openai.com/v1/organization/costs: there is noproject_idsquery 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', ... )keepsproject_id;fetch_period()requests includeproject_ids=<value>when a Project ID is configured, and omit it when not.
A PR covering this will follow.
- Dominant language
- PHP
- Stars
- 714
- Forks
- 68
- Avg merge
- 4h 32m
- Merged PRs (30d)
- 23
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 10up/classifai
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Register ClassifAI functionality with the Abilities APIPossibly taken @nhrrob claimed this 10 days ago. Openhelp wanted
Difficulty 4/5 3-5 days Newbie friendliness 48/100
10up/classifai#1249 · 1 assignee ·
Maintainers usually reply within 1 day
-
BYOK Openai modelsOpen
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
help wanted
Difficulty 4/5 3-5 days Newbie friendliness 48/100
10up/classifai#1207 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
Exclude module `require-dev` and `autoload-dev` from the generated `composer.json`Possibly taken @keiserjb claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
uiowa/uiowa#10310 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mailcow/mailcow-dockerized#7677 · 1 comment ·
Maintainers usually reply within 1 day
-
a11y
Difficulty 2/5 1-3 hours Newbie friendliness 67/100