DEV Community

ModelFild
ModelFild

Posted on

Connect LangChain to ModelFold without a workflow builder

I work on ModelFold. This walkthrough shows the configuration from our public API docs; I haven’t run a billed model call for this article.

If your workflow is already a Python function, you don’t need an n8n or Make scenario just to send a message. LangChain’s ChatOpenAI adapter can point at ModelFold’s OpenAI-compatible chat endpoint. The distinction that matters: give the adapter the base URL, not the full URL you would give curl.

Send one message

In your Python environment, install the adapter with python -m pip install -U langchain-openai. Set MODELFOLD_API_KEY through your shell’s secret manager or your deployment environment. Don’t paste the key into the script or a notebook you intend to share.

import os
from langchain_openai import ChatOpenAI

chat = ChatOpenAI(
    base_url="https://modelfold.ai/v1",
    api_key=os.environ["MODELFOLD_API_KEY"],
    model="gpt-6-luna",
    use_responses_api=False,
    max_retries=0,
)

if __name__ == "__main__":
    reply = chat.invoke([("user", "Reply with OK and nothing else.")])
    print(reply.content)
Enter fullscreen mode Exit fullscreen mode

use_responses_api=False selects Chat Completions. The adapter adds /chat/completions to the base URL. max_retries=0 makes the first failure visible instead of silently retrying during setup. Running the example makes a real model request; check the current rate before running it.

Put the call in your existing pipeline

Save the example as model_client.py. A pipeline can import chat without sending the setup prompt: the call above is inside the __main__ guard. For example, a release script could turn a supplied changelog into a short summary:

from model_client import chat

def summarize_changes(changelog: str):
    return chat.invoke([
        ("system", "Summarize only the supplied changes. Do not invent fixes."),
        ("user", changelog),
    ]).content
Enter fullscreen mode Exit fullscreen mode

If setup fails, check the symptom before changing the code. A Python KeyError for MODELFOLD_API_KEY happens before any HTTP request. For an HTTP 401, check the key configured for that process without printing it. For a 404, check the base URL first, then copy the exact model ID from the catalog. A successful text reply tests text chat, not embeddings or tool calling.

References: ModelFold chat endpoint and model ID · Gateway and model discovery.

Top comments (0)