Documentation / Connect

Connect → LangChain

Use AxForge with LangChain

LangChain builds chains and agents around a chat model. Its ChatOpenAI class takes a base URL, so an AxForge model drops in wherever a model goes: chains, tools, agents, LangGraph.

Before you start
  • An AxForge API key, in the environment variable AXFORGE_API_KEY. Get one (a minute).
  • Python 3.10 or newer. Run with langchain-openai 1.7.2 (langchain-core 1.6.12) on 2026-10-17.

Set it up

  1. Install the OpenAI package for LangChain

    pip install langchain-openai
  2. Point ChatOpenAI at AxForge

    import os
    from langchain_openai import ChatOpenAI
    
    llm = ChatOpenAI(
        base_url="https://api.axforge.ai/v1",
        api_key=os.environ["AXFORGE_API_KEY"],
        model="qwen3.8-27b-nvfp4",
    )
    print(llm.invoke("Say hello in five words").content)
  3. Run it

    python hello.py
    The LangChain script shown in a terminal and run, printing a five-word hello

From here llm is a LangChain chat model like any other: llm.stream(...), llm.bind_tools([...]), or pass it to an agent.

The settings

ArgumentValue
base_urlhttps://api.axforge.ai/v1
api_keyyour AxForge key
modelqwen3.8-27b-nvfp4, glm-5.3-flash or mimo-v2.6-flash

Which model for what: qwen3.8-27b-nvfp4 is the everyday default and reads images, glm-5.3-flash thinks before it answers, mimo-v2.6-flash is the fastest. All three can call tools.

Check that it works

The script prints an answer. The call shows in the console under API Keys → Recent calls within a minute.

When it does not work

What you seeWhat it meansFix
AuthenticationError, 401 "Invalid API key. Create one at https://console.axforge.ai/keys."the key was refusedcheck AXFORGE_API_KEY holds the whole key, or make a new one
KeyError: 'AXFORGE_API_KEY'the variable is not set in this terminalset it as on Get your API key
NotFoundError, 404the base URL has no /v1use https://api.axforge.ai/v1

Test a call says in one click whether a problem is your key, your balance or us.

Ask on the forum Markdown For AI Updated 2026-10-17

Anything unclear on this page?

Ask on the forum. The answer helps the next person too.

Ask about this page