Skip to content

LangChain ​

LangChain's ChatOpenAI client speaks the OpenAI Chat Completions API, so it routes through Corveil with two parameters.

Mode ​

Direct mode only.

1. Install ​

bash
pip install langchain langchain-openai

2. Minimal example ​

python
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="or-claude-haiku-4.5",
    base_url="https://your-corveil-host/v1",
    api_key="sk-citadel-your-key-here",
)

print(llm.invoke("Explain zero-trust architecture in one paragraph").content)

Embeddings ​

OpenAIEmbeddings calls POST /v1/embeddings on the same base URL and virtual key. An org admin first enables the model under AI Gateway → Providers → Catalog (openai/text-embedding-3-small, openai/text-embedding-3-large, or openai/text-embedding-ada-002).

The catalog names carry an openai/ prefix. To keep LangChain's default model name, the admin also clicks Add OpenAI embedding aliases under AI Gateway → Providers → Aliases. That maps text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002 onto the enabled catalog rows, so no client change is needed:

python
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    model="text-embedding-3-small",  # or "openai/text-embedding-3-small" without the alias
    base_url="https://your-corveil-host/v1",
    api_key="sk-citadel-your-key-here",
)

print(embeddings.embed_query("Explain zero-trust architecture")[:3])

By default OpenAIEmbeddings tokenizes input and sends token ids. Corveil decodes them back to text before guardrails run and sends the text upstream, so check_embedding_ctx_length can stay at its default. Token ids are accepted for the three OpenAI models above; for any other model, set check_embedding_ctx_length=False so LangChain sends strings.

Request logs record both names: the one the client sent (requested_model) and the catalog model it resolved to (resolved_model).

Notes ​

  • Anything LangChain builds on top of ChatOpenAI — agents, tools, retrievers — will inherit Corveil routing automatically
  • OpenAIEmbeddings uses the same base URL and key; retrievers that embed through it inherit Corveil routing too