Skip to main content

LLMs

Large Language Models (LLMs) are a core component of LangChain. LangChain does not serve its own LLMs, but rather provides a standard interface for interacting with many different LLMs.

All LLMs implement the llms.Model interface:

// Model is an interface multi-modal models implement.
type Model interface {
// GenerateContent asks the model to generate content from a sequence of
// messages. It's the most general interface for multi-modal LLMs that support
// chat-like interactions.
GenerateContent(ctx context.Context, messages []MessageContent, options ...CallOption) (*ContentResponse, error)

// Call is a simplified interface for a text-only Model, generating a single
// string response from a single string prompt.
//
// Deprecated: this method is retained for backwards compatibility. Use the
// more general [GenerateContent] instead.
Call(ctx context.Context, prompt string, options ...CallOption) (string, error)
}

The interface provides two methods:

  • GenerateContent: The modern, recommended method that supports multi-modal inputs and complex message sequences
  • Call: A legacy method for simple text-to-text generation (deprecated but still supported)

For backwards compatibility, llms.LLM is provided as a type alias:

// LLM is an alias for model, for backwards compatibility.
// Deprecated: This alias may be removed in the future; please use Model instead.
type LLM = Model

Supported providers

Each provider lives in its own package under github.com/vxcontrol/langchaingo/llms and implements the same llms.Model interface, so switching providers only changes construction, not your calling code:

ProviderPackageNotes
OpenAIllms/openaiAlso the client for OpenAI-compatible APIs (Groq, DeepSeek, OpenRouter, NVIDIA, Ollama Cloud, …) via WithBaseURL
Anthropicllms/anthropicClaude models, extended thinking
Google Geminillms/googleaiGoogle AI Studio endpoint
Vertex AIllms/googleai/vertexGemini through Google Cloud
AWS Bedrockllms/bedrockClaude, Llama, Titan, Nova and more
Mistralllms/mistral
Ollamallms/ollamaLocal models
Hugging Facellms/huggingface
Fakellms/fakeScripted responses for tests

Provider-neutral call options

Options passed to GenerateContent (or llms.GenerateFromSinglePrompt) work across providers; the adapter maps each to the target provider's wire format:

  • Sampling: llms.WithTemperature, llms.WithTopP, llms.WithTopK, llms.WithMaxTokens, llms.WithN.
  • Reasoning (thinking): llms.WithReasoning, llms.WithAdaptiveReasoning, llms.WithReasoningDisabled — see Configure LLM Providers.
  • Structured output: llms.WithStructuredOutput requests schema-constrained JSON and validates the response against your schema.
  • Streaming: llms.WithStreamingFunc receives a streaming.Chunk per token.
  • Tools / function calling: llms.WithTools.