LangChain (Python)
Overview
Section titled “Overview”Floopy is a zero-SDK gateway. The langchain-openai package already supports custom base URLs, so you can route all LangChain requests through Floopy without any extra dependencies. You get caching, rate limiting, fallbacks, and observability for free.
Installation
Section titled “Installation”pip install langchain-openaipoetry add langchain-openaiConfiguration
Section titled “Configuration”from langchain_openai import ChatOpenAIimport os
llm = ChatOpenAI( base_url="https://api.floopy.ai/v1", api_key=os.environ["FLOOPY_API_KEY"], # starts with fp_ model="gpt-4o",)Set FLOOPY_API_KEY in your environment. You can create one in the dashboard.
Basic Request
Section titled “Basic Request”response = llm.invoke("Explain quantum computing in one sentence.")print(response.content)Switch providers by changing the model name:
llm_anthropic = ChatOpenAI( base_url="https://api.floopy.ai/v1", api_key=os.environ["FLOOPY_API_KEY"], model="claude-sonnet-4-20250514",)
response = llm_anthropic.invoke("Hello!")Streaming
Section titled “Streaming”for chunk in llm.stream("Write a short poem about AI."): print(chunk.content, end="")Custom Headers
Section titled “Custom Headers”Pass Floopy-specific headers using default_headers:
llm = ChatOpenAI( base_url="https://api.floopy.ai/v1", api_key=os.environ["FLOOPY_API_KEY"], model="gpt-4o", default_headers={ "Floopy-Cache": "semantic", "floopy-property-environment": "production", "floopy-property-feature": "chat", "floopy-fallback": "claude-sonnet-4-20250514", },)| Header | Description |
|---|---|
Floopy-Cache | Cache strategy: semantic or exact |
floopy-property-* | Attach custom metadata for filtering in the dashboard |
floopy-fallback | Fallback model if the primary provider fails |
floopy-session-id | Group related requests into a session |
floopy-user-id | Associate requests with an end user |
See the Headers Reference for the full list.