Skip to main content

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

PyPI version License

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_id exposure on response_metadata.
  • Native support for Ferro extras: route_tag, template_id, template_variables.
  • trace_id is the join key for the v1.2 observability bridge plugins (LangSmith, Langfuse, Phoenix, Datadog, …) shipping from the ferro-labs/ai-gateway-plugins repo — 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

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_ferrolabsai-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_ferrolabsai-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

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

Hashes for langchain_ferrolabsai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2e4903aca40173afe6139200a92c2ae18afe718fc28154356564b1ad4e1662af
MD5 d1edc0d5cea48248ea308138a82f1398
BLAKE2b-256 aacadc13572bf28770d063e71057f848e2d675bf0cd9468c0f8eb79b233f51ed

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file langchain_ferrolabsai-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_ferrolabsai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c24f249c9af9e5f8d2cdfec053f8eb7700074cd8d0612221b2819a3253fad5d9
MD5 ecf998a4f0187cf17ec5d8bd00f5d36d
BLAKE2b-256 b145c726dadbb84d8c4ad0fcede1aaec8f9aedff00bbcaf70a5b781d9d385bd0

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page