Use LangChain with Shannon
Use ChatOpenAI with Shannon's base URL; chains, agents and tool binding work unchanged.
- Tested Nov 7, 2026
- OpenAI Chat Completions
- About 2 min
About LangChain
LangChain is an open-source framework for building applications and agents on language models, in Python and JavaScript. ChatOpenAI from the langchain-openai package takes a base URL, so LangChain chains, agents and LangGraph graphs can run on Shannon models.
What you need
- A Shannon API key
- Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Every snippet below follows your choice.
Set it up
-
Install the OpenAI integration
Shellpip install langchain-openai -
Create the model
ChatOpenAItakes Shannon's base URL and key; everything built on it (chains, agents, LangGraph) follows.Pythonfrom langchain_openai import ChatOpenAI llm = ChatOpenAI(model="Kimi-K3-uncensored-NVFP4", base_url="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY") print(llm.invoke("Say hello to a dog in five words.").content) -
Bind tools
Pythondef get_weather(city: str) -> str: """Weather for a city.""" ... msg = llm.bind_tools([get_weather]).invoke("What is the weather in Rome?") print(msg.tool_calls) # [{'name': 'get_weather', 'args': {'city': 'Rome'}, ...}]
Check that it works
Send: Run the first sample.
You should see: A five-word greeting, e.g. "Hello, good dog, nice pup!"
Models that fit LangChain
Every id below meets what LangChain needs. The first one is the default in the snippets.
| Model id | Context window | Max output | Image input |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Yes |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Yes |
shannon-3 | 196,608 | 65,536 | Yes |
shannon-coder-1 | 131,072 | 65,536 | No |
Good to know
ChatOpenAIdropsreasoning_content; read the reasoning with the OpenAI SDK directly if you need it.ChatAnthropic(base_url="https://api.shannon-ai.com", ...)reaches the Anthropic format instead.- LangChain's retrieval needs embeddings, which Shannon does not serve; pair it with a separate embedding model.
Tips
- Set
OPENAI_BASE_URLandOPENAI_API_KEYin the environment so everyChatOpenAIin the app uses Shannon without arguments. - Ask for typed results with
with_structured_output(MySchema, method="function_calling"): it goes through tool calls, which every model in the picker supports (LangChain's default method isjson_schema). - Pass
max_retriesandtimeouttoChatOpenAIfor long-running jobs. - Use
model.stream(...)orastream(...)to show answers as they are written.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
404 Not Found | base_url lacks /v1. | Use https://api.shannon-ai.com/v1. |
tool_calls is empty | A model that answered in text. | Use a model from the picker; all of them call tools. |
401 Unauthorized | The key is missing, mistyped or rotated. | Copy the key again from Keys & usage; it starts with sk-. |
context_length_exceeded / "prompt is too long" | The conversation is longer than the model's window. | Start a new chat, let the tool compact it, or pick a model with a larger window. |
insufficient_quota | Your balance cannot pay for the request. | Top up or change plan; the request is not retried by itself. |
Questions
Does LangChain work with Shannon?
Yes, through ChatOpenAI with base_url="https://api.shannon-ai.com/v1".
Does LangGraph work?
Yes: LangGraph agents take the same ChatOpenAI model.