LLMs
info
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 sequencesCall: 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:
| Provider | Package | Notes |
|---|---|---|
| OpenAI | llms/openai | Also the client for OpenAI-compatible APIs (Groq, DeepSeek, OpenRouter, NVIDIA, Ollama Cloud, …) via WithBaseURL |
| Anthropic | llms/anthropic | Claude models, extended thinking |
| Google Gemini | llms/googleai | Google AI Studio endpoint |
| Vertex AI | llms/googleai/vertex | Gemini through Google Cloud |
| AWS Bedrock | llms/bedrock | Claude, Llama, Titan, Nova and more |
| Mistral | llms/mistral | |
| Ollama | llms/ollama | Local models |
| Hugging Face | llms/huggingface | |
| Fake | llms/fake | Scripted 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.WithStructuredOutputrequests schema-constrained JSON and validates the response against your schema. - Streaming:
llms.WithStreamingFuncreceives astreaming.Chunkper token. - Tools / function calling:
llms.WithTools.
🗃️ Integrations
10 items