Skip to main content
Most providers should start with the DSL rather than a new Go adapter.

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:
For credential-aware providers such as Vertex AI, keep the runtime-specific values in keys.yaml and reference them through DSL variables:
Use base_url_override in keys.yaml when a deployment needs a regional endpoint, for example https://us-central1-aiplatform.googleapis.com.

Prefer explicit usage_fact

Current usage_fact supports three data sources:
  • source=response (default)
  • source=request
  • source=derived
Examples:

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.
For OpenAI specialized APIs, ONR already reuses a shared provider-usage helper layer for:
  • image generation and edit counts
  • speech duration and audio token estimation
  • transcription and translation response usage
  • Responses API web_search_call counting
The preferred path is:
  1. express request/response matching in the DSL,
  2. express usage with usage_fact,
  3. add native helper code only for the irreducible derived pieces.