LangChain integration for Ferro Labs AI Gateway — chat, streaming, embeddings, and tool calling across 30+ LLM providers via a single OpenAI-compatible endpoint
Project description
langchain-ferrolabsai
LangChain integration for Ferro Labs AI Gateway — route LangChain chat, streaming, tool-calling, and embedding workloads across 30+ LLM providers through a single OpenAI-compatible endpoint, with automatic fallback, load balancing, cost tracking, and observability.
Install
pip install langchain-ferrolabsai
Quick start
Chat
from langchain_ferrolabsai import FerroChatModel
from langchain_core.messages import HumanMessage
llm = FerroChatModel(
model="gpt-4o",
base_url="http://localhost:8080", # any Ferro Labs AI Gateway instance
api_key="sk-ferro-...",
)
response = llm.invoke([HumanMessage(content="Hello, world")])
print(response.content)
print(response.response_metadata["provider"]) # which provider handled it
print(response.response_metadata["cost_usd"]) # cost for this request
print(response.response_metadata["latency_ms"]) # observed latency
print(response.response_metadata["trace_id"]) # gateway trace ID (x-trace-id)
Swap providers without changing the model class — Ferro auto-routes by model name:
claude = FerroChatModel(model="claude-3-5-sonnet-20241022", base_url="...", api_key="...")
gemini = FerroChatModel(model="gemini-1.5-flash", base_url="...", api_key="...")
Streaming
for chunk in llm.stream([HumanMessage(content="Tell me a story")]):
print(chunk.content, end="", flush=True)
Tool calling / LangGraph agents
from langchain_core.tools import tool
@tool
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b
agent_llm = llm.bind_tools([add])
response = agent_llm.invoke([HumanMessage(content="What is 4 + 7?")])
print(response.tool_calls)
Embeddings
from langchain_ferrolabsai import FerroEmbeddings
embed = FerroEmbeddings(model="text-embedding-3-small", base_url="...", api_key="...")
vectors = embed.embed_documents(["hello", "world"])
query_vec = embed.embed_query("hello")
Legacy LLM interface
from langchain_ferrolabsai import FerroLLM
llm = FerroLLM(model="gpt-4o", base_url="...", api_key="...")
print(llm.invoke("Write a haiku about gateways"))
Why use this instead of ChatOpenAI(base_url=...)?
ChatOpenAI pointed at a Ferro Labs gateway works as a drop-in. This package adds:
- First-class
provider,cost_usd,latency_ms,trace_idexposure onresponse_metadata. - Native support for Ferro extras:
route_tag,template_id,template_variables. trace_idis the join key for the v1.2 observability bridge plugins (LangSmith, Langfuse, Phoenix, Datadog, …) shipping from theferro-labs/ai-gateway-pluginsrepo — any provider's calls become visible in your existing LLMOps backend without per-provider wiring.
Status & roadmap
0.1.0 is the first functional release of the adapter. See
CHANGELOG.md for what shipped and what's planned. Async
surfaces and with_structured_output() are the next two items.
Related
ferrolabsai— the core Python SDK this package wraps.- Ferro Labs AI Gateway — the open-source gateway server (v1.1.0+ OTel-native).
ai-gateway-cookbook— runnable recipes (start withpython/02-langgraph-multi-provider-agent).- Documentation
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_ferrolabsai-0.1.0.tar.gz.
File metadata
- Download URL: langchain_ferrolabsai-0.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e4903aca40173afe6139200a92c2ae18afe718fc28154356564b1ad4e1662af
|
|
| MD5 |
d1edc0d5cea48248ea308138a82f1398
|
|
| BLAKE2b-256 |
aacadc13572bf28770d063e71057f848e2d675bf0cd9468c0f8eb79b233f51ed
|
Provenance
The following attestation bundles were made for langchain_ferrolabsai-0.1.0.tar.gz:
Publisher:
publish-langchain-ferrolabsai.yml on ferro-labs/ferrolabs-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_ferrolabsai-0.1.0.tar.gz -
Subject digest:
2e4903aca40173afe6139200a92c2ae18afe718fc28154356564b1ad4e1662af - Sigstore transparency entry: 1652039205
- Sigstore integration time:
-
Permalink:
ferro-labs/ferrolabs-python-sdk@1a4562d52e0b7d5b79525b8fd4e988657efe1f0e -
Branch / Tag:
refs/tags/langchain-ferrolabsai-v0.1.0 - Owner: https://github.com/ferro-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-langchain-ferrolabsai.yml@1a4562d52e0b7d5b79525b8fd4e988657efe1f0e -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_ferrolabsai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: langchain_ferrolabsai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24f249c9af9e5f8d2cdfec053f8eb7700074cd8d0612221b2819a3253fad5d9
|
|
| MD5 |
ecf998a4f0187cf17ec5d8bd00f5d36d
|
|
| BLAKE2b-256 |
b145c726dadbb84d8c4ad0fcede1aaec8f9aedff00bbcaf70a5b781d9d385bd0
|
Provenance
The following attestation bundles were made for langchain_ferrolabsai-0.1.0-py3-none-any.whl:
Publisher:
publish-langchain-ferrolabsai.yml on ferro-labs/ferrolabs-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_ferrolabsai-0.1.0-py3-none-any.whl -
Subject digest:
c24f249c9af9e5f8d2cdfec053f8eb7700074cd8d0612221b2819a3253fad5d9 - Sigstore transparency entry: 1652039461
- Sigstore integration time:
-
Permalink:
ferro-labs/ferrolabs-python-sdk@1a4562d52e0b7d5b79525b8fd4e988657efe1f0e -
Branch / Tag:
refs/tags/langchain-ferrolabsai-v0.1.0 - Owner: https://github.com/ferro-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-langchain-ferrolabsai.yml@1a4562d52e0b7d5b79525b8fd4e988657efe1f0e -
Trigger Event:
push
-
Statement type: