API integrations

LangChain with EasyAPI

Use ChatOpenAI in an existing LangChain application with the EasyAPI endpoint. Start with a plain text call, then test streaming before adding agents or tools.

Requirements

Install the package in an isolated Python environment. Set EASYAPI_API_KEY and use the exact model ID shown in the catalog. LlamaIndex also requires EASYAPI_CONTEXT_WINDOW from the model documentation.

python -m pip install -U langchain-openai

Keep API keys in server-side environment variables or n8n credentials. Exported workflows and shared code must contain no production secrets.

Setup steps

  1. Install langchain-openai and set the API key on the server. Keep tracing disabled unless you intend to send prompts to a tracing service.
  2. Set base_url to the URL below and model to a current catalog ID. The sample disables streaming usage extensions and selects Chat Completions explicitly.
  3. Run the Python script. It prints one complete response and then a streamed response. Add tool binding only after checking that the chosen model supports it.

Runnable request

The examples use your selected public model. Model access and limits still depend on your API key and account group. deepseek-v4-pro-0813

import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    api_key=os.environ["EASYAPI_API_KEY"],
    base_url=os.environ.get("EASYAPI_BASE_URL", "https://token.easyapi.com/v1"),
    model=os.environ.get("EASYAPI_MODEL", "deepseek-v4-pro-0813"),
    use_responses_api=False,
    stream_usage=False,
    timeout=60,
    max_retries=2,
)
print(llm.invoke("Reply with one short greeting.").content)
for chunk in llm.stream("Reply with one short greeting."):
    print(chunk.content, end="", flush=True)
print()

Expected result

A successful request returns a non-empty assistant message. Check the usage record and actual charge before increasing traffic.

Compatibility and limits

This guide covers text Chat Completions. Image, video, embeddings, tools and structured output require separate model and endpoint checks. OpenAI client compatibility does not guarantee every vendor feature.

Read API documentation

Questions and troubleshooting

Can I keep my existing chains?
Keep the message and chain structure for Chat Completions. Recheck provider-specific parameters, response metadata, retries and token accounting before moving a production chain.
Why does a streaming call fail?
Confirm ordinary chat works first. This example sets stream_usage=False because OpenAI streaming usage extensions are not universal. Check the model documentation before enabling additional fields.
Does this sample run an agent?
No. It sends chat messages only. An agent also needs defined tools, tool-call handling and separate compatibility tests; no undefined tool function is required by this example.

Official sources

LangChain · Checked