LangChain + CaMeL Hub: One Key for GPT, Claude, Gemini & DeepSeek

LangChain is the most widely used Python/JS framework for building LLM applications β€” chains, agents, RAG pipelines β€” on top of a swappable chat-model interface. Point its OpenAI-compatible ChatOpenAI class at CaMeL Hub and every chain, agent, or tool you already wrote keeps working unchanged, except now model="..." can be GPT-5.5, Claude Sonnet 5, Gemini 3.1 Pro, DeepSeek V4 Flash, or any of CaMeL Hub's 480+ models β€” behind one API key, one base URL, and one bill.

LangChain β†—

  1. Install the LangChain OpenAI integration

    LangChain talks to any OpenAI-compatible endpoint β€” including CaMeL Hub β€” through the langchain-openai package. Install it alongside the base langchain package.
    pip install -U langchain langchain-openai
  2. Create a CaMeL Hub API key

    Sign in to the CaMeL Hub console and open the page usually labeled Tokens or API Keys in the left sidebar. Create a new token and copy the sk-... string immediately β€” it is shown in full only once.
  3. Point the OpenAI client config at CaMeL Hub

    LangChain's OpenAI classes read two settings: the API key and the base URL. Set them as environment variables (or pass them directly to ChatOpenAI in the next step). CaMeL Hub's OpenAI-compatible endpoint needs the full path with /v1 β€” the bare host https://api.camel-hub.com will not work here.
    export OPENAI_API_KEY="sk-your-camel-hub-key"
    export OPENAI_BASE_URL="https://api.camel-hub.com/v1"
  4. Call any model with ChatOpenAI

    Import ChatOpenAI from langchain_openai and set model to any CaMeL Hub model slug. No extra base_url argument is required if you already set the environment variables above, but you can also pass it explicitly.
    from langchain_openai import ChatOpenAI
    
    llm = ChatOpenAI(
        model="claude-sonnet-5",
        base_url="https://api.camel-hub.com/v1",  # optional if OPENAI_BASE_URL is set
        temperature=0.7,
    )
    
    response = llm.invoke("Explain what a base_url override does, in one sentence.")
    print(response.content)
  5. Switch providers by changing only the model string

    Because every provider is exposed through the same OpenAI-format endpoint, you never need LangChain's ChatAnthropic or ChatGoogleGenerativeAI classes here β€” just change the model string and keep using ChatOpenAI.
    for model in ["gpt-5.5", "claude-sonnet-5", "gemini-3.1-pro", "deepseek-v4-flash"]:
        llm = ChatOpenAI(model=model)
        print(model, "->", llm.invoke("Say hello in five words.").content)
  6. Stream tokens and use tool calling

    Streaming and tool/function calling work exactly like they do against OpenAI directly. Use .stream() for token-by-token output, and .bind_tools() for agents β€” check the Capabilities section on a model's CaMeL Hub page first to confirm it supports function calling or vision.
    for chunk in llm.stream("Write a two-line haiku about API gateways."):
        print(chunk.content, end="", flush=True)
  7. Same pattern in LangChain.js (TypeScript)

    The Node/TypeScript SDK follows the same pattern through @langchain/openai, so LangGraph.js agents and chains built on it need no other changes.
    import { ChatOpenAI } from "@langchain/openai";
    
    const llm = new ChatOpenAI({
      model: "claude-sonnet-5",
      apiKey: process.env.OPENAI_API_KEY,
      configuration: { baseURL: "https://api.camel-hub.com/v1" },
    });
    
    const res = await llm.invoke("hello");
    console.log(res.content);

Frequently asked questions

Should I use ChatAnthropic or ChatGoogleGenerativeAI for Claude or Gemini models instead of ChatOpenAI?

No. CaMeL Hub exposes a single OpenAI-compatible endpoint for every provider, so LangChain's ChatOpenAI (or init_chat_model(..., model_provider="openai")) is the only class you need β€” just change the model string. LangChain's provider-specific classes try to hit Anthropic or Google directly, and a CaMeL Hub key will not authenticate against those endpoints.

Which model name do I pass to model=?

Use the CaMeL Hub slug shown on the model's page or in the console's model list β€” for example claude-sonnet-5, gpt-5.5, or deepseek-v4-flash β€” not the vendor's own model ID. Vendor-native IDs are not recognized by the gateway.

I'm getting a 401 Unauthorized from LangChain.

Confirm OPENAI_API_KEY (or the key passed to ChatOpenAI) was copied in full with no trailing whitespace, and that OPENAI_BASE_URL / base_url ends in /v1. A base URL missing /v1 is the most common cause of "works in curl, fails in LangChain."

Do LangChain agents and tool calling (bind_tools) work through CaMeL Hub?

Yes, for any model whose CaMeL Hub page lists function-calling under Capabilities. The OpenAI-compatible endpoint forwards tool schemas and tool_call responses the same way OpenAI's API does, so bind_tools(), create_tool_calling_agent, and LangGraph agents work unchanged.