Skip to content

ainfera-ai/ainfera-langchain

ainfera-langchain — LangChain + Ainfera Routing

LangChain integration + Ainfera Routing. Working agent in ~30 lines. Clone, install, run.

Quickstart

git clone https://github.com/ainfera-ai/ainfera-langchain
cd ainfera-langchain
pip install -r requirements.txt
export AINFERA_API_KEY=ai_infera_...  # https://app.ainfera.ai/signup
python main.py

Or with curl only — no LangChain install:

./curl-example.sh   # signup → inference → audit verify

What this shows

  • One Agent Card across providers (L1)
  • Routed inference with per-call budget caps (L3)
  • Audit URL printed after every call (L4)
  • Quality scored by Artificial Analysis per model

EU AI Act Annex IV ready — every call hash-chained, signed, exportable.

The whole change

LangChain speaks OpenAI's API. Two env vars and your existing ChatOpenAI code routes through Ainfera:

from ainfera_callback import AinferaCallbackHandler

handler = AinferaCallbackHandler()
chat = ChatOpenAI(
    model="claude-opus-4-7",
    openai_api_key=os.environ["AINFERA_API_KEY"],
    openai_api_base="https://api.ainfera.ai/v1",
    callbacks=[handler],
)
# handler.last_audit_url after each invoke

That's it.

Callback observability (LC-02)

AinferaCallbackHandler reads the ainfera extension block and x-ainfera-* headers returned by POST /v1/chat/completions:

handler = AinferaCallbackHandler()
# after invoke:
print(handler.last_audit_url)
print(handler.last_inference_id, handler.last_agent_id)

Open the audit chain

After running, visit https://verify.ainfera.ai/agents/<your-agent-id> to see the hash-chained audit trail. Every call has a verifiable receipt.

Other frameworks

Apache 2.0. © Ainfera Inc. 2026.

About

LangChain integration + Ainfera Routing. Working agent in ~30 lines. 2 env vars.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors