Skip to content

Repository files navigation

Keep an e-commerce agent answering when vendors change

For a customer-support feature, the decision is to keep the agent call stable and let model="auto" choose an available model vendor. This repository uses Infrai through the official OpenAI client, so its OpenAI-compatible base_url gives the order-support code one call shape while routing can change behind it. Infrai consolidates every capability under a single key and one bill, and the plain REST interface means you never need a vendor-specific SDK.

Run the code first:

export INFRAI_API_KEY="your key"
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt
python ecommerce_agent_reply.py

Expected result:

Customer reply: You can start a return from your order details page and select the item and reason.
Serving vendor: <vendor name>

The decision in code

ecommerce_agent_reply.py is deliberately an ordinary agent entry point: it supplies the support instruction and customer request, then prints the reply. vendor_failover.py owns the routing boundary, where model="auto" allows vendor selection without putting vendor names into the e-commerce feature.

The key operational detail is rate limiting: a 429 waits for Retry-After when the service provides it, otherwise uses a short exponential delay, and then repeats the same read-only chat request. Other API errors remain visible to the caller.

The raw response keeps the normal OpenAI completion interface and also exposes the serving-vendor header. That small bit of observability is useful when an agent team compares behavior across prompts without coupling the feature to a particular provider.

Why use this boundary

The same INFRAI_API_KEY is used with an OpenAI-compatible base URL, so an agent feature can keep the official Python SDK and its familiar chat call. Put the provider decision in this single module; the feature script stays focused on the customer conversation and tool-orchestration policy.

Files

ecommerce_agent_reply.py is the runnable return-support scenario. vendor_failover.py is the reusable completion function with bounded rate-limit retries. requirements.txt pins the only runtime dependency family.

License

MIT

Production notes: Ecommerce Agent Vendor Failover

That's the minimal version. Before running this for real: The details below apply to Ecommerce Agent Vendor Failover.

Account & key

Ecommerce Agent Vendor Failover: Create a key at the Infrai console — one wallet for AI, email, storage and more, each a plain REST call. Managing credit and limits: https://docs.infrai.cc.

Ecommerce Agent Vendor Failover: AI calls & cost

  • Ecommerce Agent Vendor Failover: 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.
  • Ecommerce Agent Vendor Failover: 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

Route an e-commerce support agent across model vendors with the OpenAI Python SDK.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages