Start with the DSL
Use the provider DSL to describe request routing, response mapping, and usage extraction first. Add native Go code only when the provider requires request/response rewriting or runtime-derived metrics that the DSL cannot express yet. Typical skeleton:Prefer explicit usage_fact
Current usage_fact supports three data sources:
source=response(default)source=requestsource=derived
When native code is still needed
Keep native Go code as small as possible and treat it as a provider-specific usage derivation helper, not a second billing system. Native code is still appropriate when:- the provider returns binary output and usage must be derived from bytes or media duration;
- the provider uses stream or realtime event aggregation;
- the provider requires request rewriting that the DSL cannot express cleanly yet.
- image generation and edit counts
- speech duration and audio token estimation
- transcription and translation response usage
- Responses API
web_search_callcounting
- express request/response matching in the DSL,
- express usage with
usage_fact, - add native helper code only for the irreducible derived pieces.