For a Claude integration on CometAPI, choose the usage parser by the endpoint contract—not simply by the model name. If the adapter is configured for CometAPI’s Anthropic Messages route, treat message_delta.usage token counts as cumulative snapshots, not increments to add together.
CometAPI’s Messages documentation specifies POST /v1/messages, configures the Anthropic SDK with base_url="https://api.cometapi.com", and shows client.messages.stream(...) with stream.get_final_message(). Make the adapter’s routing assertion check that exact base URL and /v1/messages destination before selecting the Messages parser. The page points OpenAI-compatible requests to a separate Chat Completions surface, so a move there must fail that assertion and require a separate parser check—not reuse based on the Claude model name.
The rule itself comes from Anthropic’s streaming contract: token counts in message_delta’s usage field are cumulative. Adding those snapshots repeatedly counts earlier tokens again. This is an upstream protocol guarantee, not a claim that a live CometAPI route has been tested here.
Before using this adapter’s output for usage reporting, I would make these acceptance checks:
- Verify the configured destination is CometAPI’s
/v1/messages, then assert that the selected response has the Anthropic Messages event shape (includingmessage_deltausage andmessage_stop) before dispatching it to this parser. A Chat Completions response must take a separate parser path. - Feed the Messages adapter a synthetic fixture, not a claimed service response, with successive
message_delta.usage.output_tokensvalues of4,9, and12, followed bymessage_stop. The expected completed output-token count is12, not25. Replace the stored value for each reported field rather than adding snapshots; a missing field should not erase an earlier value. - On an authorized integration test against that selected CometAPI route, compare the adapter’s completed count with the completed Message’s
usage.output_tokenswhen available. Keep an interrupted stream’s latest count marked provisional rather than presenting it as a completed total. These are proposed checks, not executed results.
This decision concerns output-token accounting, not invoice reconciliation. Keep input and cache usage fields separate, and do not translate the synthetic overcount into a savings claim. The useful boundary is narrow: CometAPI’s documented /v1/messages routing and event shape select the adapter; Anthropic supplies the cumulative-event semantics; the route-specific acceptance test checks that the integration preserves them.