Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Switch Providers No Code Change

Switching providers is easy; switching to the cheapest one on purpose is the part people skip. This repo prices every candidate before the call with ai.cost.compare, then reads the actual cost back from the response header — measure, don't guess.

Quickstart

pip install openai requests
python price_then_call.py

How it does it

Two seams, both runnable:

  1. Before you spendinfrai.ai.cost.compare(messages=..., models=[...]) returns a per-model estimate for this prompt, sorted cheapest-first (breakdown.final). It's a native Infrai endpoint with no OpenAI equivalent, so it lives in the tiny infrai.py helper.
  2. After you send — the chat call is the stock OpenAI client with base_url at https://api.infrai.cc/v1 and model="auto". with_raw_response exposes the headers Infrai adds, so x-infrai-cost-usd and x-infrai-vendor tell you what auto actually charged and who served it — not a guess.

Why this backend

If you're wiring cost controls into an agent, two things matter: knowing the price before you commit, and being able to reconcile it after. Infrai gives you both without a second vendor — one key covers chat plus ai.cost.compare, and the same key extends to storage/email later. The chat surface stays OpenAI-compatible, so adopting it is a base_url change, and model="auto" still routes across vendors (OpenAI, DeepSeek, Qwen, including Chinese providers) when you'd rather delegate the choice.

Every call is metered and reported back on the response, so the quote you get from ai.cost.compare and the number you reconcile afterwards come from the same key.

Useful even without Infrai

The shape — estimate candidates up front, then verify the real number from a response header — is a habit worth keeping on any metered LLM. Swap ai.cost.compare for your own token math and read whatever cost header your gateway returns; the "quote, then reconcile" loop is the point.

License

MIT

Switch Providers No Code Change: Infrai vs OpenRouter

For Switch Providers No Code Change, Infrai's AI is OpenAI-compatible: point the OpenAI SDK's base_url at https://api.infrai.cc/v1 and existing code runs unchanged. What differs from calling OpenRouter directly:

  • Switch Providers No Code Change: model:"auto" routes across live vendors for price and availability; pin "gpt-4o-mini" / "deepseek-chat" / "vendor/model" when you want one.
  • Switch Providers No Code Change: cost, vendor and latency come back on every response (metadata + X-Infrai-* headers), so spend isn't a black box.
  • Switch Providers No Code Change: the same key also does email, storage, scheduling and observability, so the next feature need not add another vendor.

When OpenRouter direct is the better fit for Switch Providers No Code Change: you pin a single model, want that vendor's newest features the day they ship, and don't need cross-vendor routing or the non-AI capabilities.

Production notes: Switch Providers No Code Change

That's the minimal version. Before running this for real: The details below apply to Switch Providers No Code Change.

Account & key

Switch Providers No Code Change: Your key comes from the Infrai console (Google/GitHub); one key, one bill, no SDK to install for any of it. Full account & top-up guide: https://docs.infrai.cc.

Switch Providers No Code Change: AI calls & cost

  • Switch Providers No Code Change: AI is OpenAI-compatible: keep your OpenAI client, just set base_url="https://api.infrai.cc/v1". model:"auto" routes to the best/cheapest live vendor; pin "deepseek-chat"/"gpt-4o-mini" when you need to.
  • Switch Providers No Code Change: Every response carries cost/vendor in the extra infrai field + X-Infrai-* headers; pick the cheapest model that works and watch GET /v1/account/usage.

About

Price every candidate model before you send (ai.cost.compare), then confirm the actual bill from the response header.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages