The runtime shared by every Elixir SDK generated with Infusion.
You don't use this package directly: an SDK generated by Infusion depends on it, and its generated functions hand each API call to it. Keeping this code out of the generated SDKs means a fix here reaches every SDK, and the generated code stays short and readable.
What it does, built on Req:
- Requests: base URL, auth (bearer, basic, API key header or query),
JSON, nested form (
metadata[key]=value) and multipart bodies, per-call options - Retries like the official SDKs: connection errors, timeouts, 408,
409, 429 and 5xx;
retry-after-ms,retry-after,x-should-retry; capped exponential backoff with jitter; idempotency keys reused across retries - Decoding JSON into the SDK's structs, with real union types and
unknown fields kept in
__extra__ - Streaming Server-Sent Events as a lazy
Streamof decoded events - Pagination as a lazy
Streamof every item: cursors, page numbers, offsets, next-page URLs andLinkheaders - Errors as one struct,
Infusion.Runtime.Error, with atype(:rate_limit,:not_found, ...), status, body and request ID Telemetry:
[:infusion, :request, :start | :stop | :exception]
Configuration
Settings come from the SDK's defaults, then your config, then the call:
config :openai_sdk, api_key: System.fetch_env!("OPENAI_API_KEY"), max_retries: 5
OpenAI.Models.list(timeout: 5_000)See Infusion.Runtime.Config for every setting.
Testing
Point an SDK at a Req.Test stub:
# config/test.exs
config :openai_sdk, req_options: [plug: {Req.Test, OpenAI}]License
Apache 2.0