LangChain

A framework for orchestrating LLMs

LangChainarrow-up-right is a framework for building and deploying applications powered by large language models (LLMs), streamlining the entire lifecycle from development to production.

It offers open-source components and integrations for building applications, LangGraph for creating stateful agents with streaming and human-in-the-loop support, and LangSmith for inspecting, monitoring, and evaluating performance to ensure optimization.

Finally, with LangGraph Platform, developers can deploy their applications as production-ready APIs and Assistants.

This guide will walk you through the setup.

circle-info

Before you begin: Make sure you have generated your Cortecs API key. If not, check out our QuickStart guide.

1. Install LangChain

LangChain offers both Pythonarrow-up-right and JavaScriptarrow-up-right libraries.

To get started quickly, follow the installation instructions in the documentation for your preferred language.

Once the framework is installed, you can begin building applications by connecting to an external provider.

2. Connect to cortecs

Cortecs provides OpenAI-compatible API endpoints, making it easy to integrate with LangChain and many other tools.

To connect and use the LLM, create an ChatOpenAI object, with the following settings:

api_key: Your API Key – base_url: https://api.cortecs.ai/v1model: gpt-5-mini (feel free to pick another one from the cataloguearrow-up-right) – (optional) extra_body: {"preference": "balanced"}

from langchain_openai import ChatOpenAI
from pydantic import SecretStr

llm = ChatOpenAI(
    model="gpt-5-mini",
    # you also can use env vars to configure base_url and api_key
    api_key=SecretStr("eyJhbG***"),
    base_url="https://api.cortecs.ai/v1",
    extra_body= {"preference": "balanced"}
)

print(llm.invoke("Hi").content)

2.1. Embedding Model

To create embeddings and use LangChain with vector databases, you can instantiate an OpenAIEmbeddings object with the following settings:

api_key: Your API Key – base_url: https://api.cortecs.ai/v1model: text-embedding-3-large (feel free to pick another embedding model from the cataloguearrow-up-right) – (optional) model_kwargs: {"extra_body": {"preference": "balanced"}}

Enjoy your privacy-preserving LLM applications with the power of Cortecs and LangChain. Explore other models, tweak the setup to your needs, and join the conversation on our Discordarrow-up-right to share feedback 👩‍💻👨‍💻

Last updated