A stream that produces readable text has not necessarily produced the telemetry needed to attribute its cost. If you use @ai-sdk/openai-compatible with CometAPI, check the provider’s usage opt-in before treating an empty usage record as an accounting result.
The AI SDK compatible-provider documentation lists includeUsage as a provider-instance setting, with a default of undefined (false). Its purpose is to include usage information in streaming response metadata. That is a useful configuration check—not proof that this setting caused a particular missing record, or that enabling it guarantees usable metadata from every route.
Apply the setting to the right CometAPI interface
CometAPI’s integration article documents two separate paths:
| Interface | Endpoint | Client base URL |
|---|---|---|
| OpenAI-compatible Chat Completions | /v1/chat/completions |
https://api.cometapi.com/v1 |
| Native Anthropic Messages | /v1/messages |
https://api.cometapi.com |
This recommendation concerns the Chat Completions path with @ai-sdk/openai-compatible, not the native Messages interface or every AI SDK provider. Keep that distinction in your configuration: the compatible-provider base URL is the prefix, not the full Chat Completions endpoint.
An illustrative provider configuration, adapted from the AI SDK documentation, is:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
const cometapi = createOpenAICompatible({
name: 'cometapi',
apiKey: process.env.COMETAPI_API_KEY,
baseURL: 'https://api.cometapi.com/v1',
includeUsage: true,
});
This is a configuration sketch, not a tested end-to-end integration. Supply your selected model ID in the subsequent model call and validate that route before relying on its usage output.
CometAPI explicitly cautions that a compatible endpoint does not remove the need for regression tests around streaming and model-specific parameters. Its article establishes the connection path; it does not establish which usage fields a selected route returns or how your installed AI SDK version exposes them.
Validate the accounting boundary, not just the text
Before using streamed requests in a cost report, I would use this small acceptance checklist:
- Record the configuration under test: SDK package/version, CometAPI endpoint, selected model ID, and whether
includeUsageis enabled. Keep credentials out of the test record. - Inspect a completed stream: distinguish usage returned by the route from usage exposed by the SDK. Check that the fields your accounting code needs are present and interpretable; text output alone is not the acceptance criterion.
- Check an interrupted stream separately: do not assume its usage record has the same completeness as a normally completed request. Preserve completion status alongside usage availability.
- Repeat for each model route you intend to attribute costs to: do not promote a successful check on one route into a guarantee for another.
These are proposed validation steps, not reported test results. Neither cited source supplies request traces demonstrating this integration’s streaming usage behavior.
Missing usage is not zero cost
Keep three outcomes separate in downstream accounting:
- Text returned, usage missing or unusable: retain an explicit unknown-usage state. Do not silently substitute zero tokens or zero cost.
- Text returned, usable usage present: allow an estimate only after checking applicable pricing and how those usage categories map to it.
- Billing reconciled: require separate billing evidence. Usage metadata alone does not establish this outcome.
The practical decision is to enable includeUsage explicitly on this CometAPI Chat Completions integration, then gate cost attribution on route-specific validation. That prevents a UI success from being mistaken for a complete cost record without promising that one flag fixes every missing-telemetry case.