LangChain
LangChain is a framework for building LLM applications and agents. Its ChatOpenAI class talks to
Bayle once you change the base URL.
Copies this page's setup instructions, to paste into your coding agent.
Show the prompt
Help me set this up to use Bayle AI, an OpenAI-compatible API. Full guide: https://docs.bayle.ai/guides/sdks/langchain/
Goal: use Bayle models in my LangChain (https://www.langchain.com) code through ChatOpenAI.
1. Install the package if `python -c "import langchain_openai"` fails:
pip install langchain-openai
2. Pick a model. For tools, choose one that supports function calling:
curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'
curl -s "https://api.bayle.ai/models?type=text" \
| jq -r '.data[] | select(.model_spec.capabilities.supportsFunctionCalling) | .id'
Show me the lists, let me choose, and use that id as MODEL_ID.
3. In my code, build the model like this. `use_responses_api=False` is required: without it ChatOpenAI switches to OpenAI's Responses API for some parameters and model names, and Bayle serves chat completions only. For a reasoning model pass `reasoning_effort=`, not `reasoning=`:
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="MODEL_ID",
base_url="https://api.bayle.ai",
api_key=os.environ["BAYLE_API_KEY"],
use_responses_api=False,
)
Tools work the usual way with llm.bind_tools([...]). ChatOpenAI drops response fields it does not know, such as reasoning_content.
4. Verify by running:
print(llm.invoke("In one sentence, what is an embedding?").content)
and show me the output.
Rules:
1. The base URL is https://api.bayle.ai exactly as written. Append no path to it.
2. Read the key from the BAYLE_API_KEY environment variable. Never write the key itself into a file you create, a command, a commit or the chat. Where the tool keeps the key in its own settings screen, tell me where to paste it. If BAYLE_API_KEY is not set, stop and ask me to create a key at https://chat.bayle.ai/developers and export it.
3. Take model ids only from GET https://api.bayle.ai/models (no key needed). Never guess one.
4. Finish with one real test request, show me the result and list the files you changed.Install
Section titled “Install”pip install langchain-openaiSee the official ChatOpenAI guide
for installation and the other options.
Don't have a Bayle key yet?Get API key
import osfrom langchain_openai import ChatOpenAI
llm = ChatOpenAI( model="MODEL_ID", base_url="https://api.bayle.ai", api_key=os.environ["BAYLE_API_KEY"], use_responses_api=False,)
print(llm.invoke("In one sentence, what is an embedding?").content)- Set
use_responses_api=False. Without it,ChatOpenAIswitches to OpenAI’s Responses API for some parameters (such asreasoning=) and model names, and Bayle serves chat completions only. For a reasoning model, passreasoning_effort=instead ofreasoning=. ChatOpenAIdrops response fields it doesn’t know, such asreasoning_content.
Tools work the usual way, with llm.bind_tools([...]), on a model that supports function
calling.
Pick a model
Section titled “Pick a model”curl -s "https://api.bayle.ai/models?type=text" | jq -r '.data[].id'