Skip to content

build_llm

identity.build_llm(BaseClass) is the single entry point for constructing a proxy-routed LLM. It dispatches on the base class and returns a dynamic subclass whose constructor injects the proxy URL and a RunVault-aware httpx client.

RVChat = identity.build_llm(ChatOpenAI)
llm = RVChat(model="gpt-4o-mini")

Inherited methods (.invoke(), .stream(), .bind_tools(), async, batching) work unchanged. Tool-binding, streaming, structured output, isinstance checks — all behave as upstream.

Dispatch table

Base class Required extra
langchain_openai.ChatOpenAI runvault[langchain-openai]
langchain_anthropic.ChatAnthropic runvault[langchain-anthropic]
langchain_google_genai.ChatGoogleGenerativeAI runvault[langchain-google]
openai.OpenAI runvault[openai]
openai.AsyncOpenAI runvault[openai]
Any subclass of crewai.BaseLLM runvault[crewai]

User subclasses of any supported class are picked up through MRO. Unknown classes raise TypeError.

Identity binding

Every wired client is bound to the identity that built it. That identity's key signs every JWT the client mints — even if a different identity owns the active run. The cross-identity guard fires in that case (see Authentication).

Per-framework recipes

See LLM Clients for ready-to-paste examples for each supported framework.


Reference

runvault.llm.build_llm(identity, base_cls)

Return a dynamic subclass of base_cls wired through the proxy.

The returned class behaves exactly like base_cls except that its constructor injects RunVault's proxy URL and httpx clients. All inherited methods (.invoke(), .stream(), .bind_tools(), etc.) keep working unchanged.

Parameters:

Name Type Description Default
identity 'Identity'

The Identity whose proxy URL and credentials to wire in.

required
base_cls type

The LLM class to extend (e.g. ChatOpenAI).

required

Returns:

Type Description
type

A subclass of base_cls.

Raises:

Type Description
TypeError

If base_cls is not in the dispatch table and is not a CrewAI BaseLLM subclass.