Documentation
¶
Overview ¶
Package mistral wraps Mistral AI's API.
Mistral exposes:
- /chat/completions — native structured content and thinking chunks, used via NewChat;
- /embeddings — OpenAI-compatible, used via NewEmbeddingModel (returns an openai.EmbeddingModel);
- /moderations — Mistral-native shape that doesn't match OpenAI's moderation response; NewModerationModel handles it directly against [API] from this package.
Additional Mistral surfaces not exposed here:
- /agents (stateful agent runs);
- /fim (code completion endpoint; it is not modeled by the chat facade).
Stream termination. A chunk carrying finish_reason is the only claim that the answer is whole; the closing [DONE] marker is not, and neither is a body that simply ends. A stream that stops without one fails with [chat.ErrInvalidResponse] rather than handing back the fragment it did deliver. finish_reason model_length is the model's own context filling rather than the caller's budget, and both report as a truncation.
Finish reasons. Mistral's own client types the field as stop, length, model_length, error or an unrecognized string. error and an unrecognized value both map to [chat.FinishReasonOther] — a known terminal state with no portable match — and the provider's own word for it rides along on the output, so an errored generation stays distinguishable from a provider limit. error used to reach Other through a default branch, which files a documented value under "not classified", and the synchronous path dropped the native value the streaming path already kept.
See https://docs.mistral.ai/ for the full API reference.
Index ¶
Constants ¶
const ( // ModelMedium is the current frontier-class model with adjustable reasoning. ModelMedium = "mistral-medium-3-5" // ModelSmall is the current hybrid instruct, reasoning, and coding model. ModelSmall = "mistral-small-2603" // ModelLarge is Mistral Large 3. ModelLarge = "mistral-large-2512" // ModelCodestral targets code generation and fill-in-the-middle. ModelCodestral = "codestral-2508" ModelMinistral3B = "ministral-3b-2512" ModelMinistral8B = "ministral-8b-2512" ModelMinistral14B = "ministral-14b-2512" // ModelPixtralLarge remains the supported Pixtral Large model. ModelPixtralLarge = "pixtral-large-2411" )
Current chat model ids. See https://docs.mistral.ai/models/.
const ( // ModelEmbed (mistral-embed) is the general-purpose embedding // model. 1024-dim by default; pass [embedding.Options.Dimensions] // to truncate. ModelEmbed = "mistral-embed" // ModelCodestralEmbed is the code-tuned // embedding model. ModelCodestralEmbed = "codestral-embed-2505" )
Embedding model ids.
const (
DefaultBaseURL = "https://api.mistral.ai/v1"
)
Exported defaults keep constructor behavior visible and overridable.
const ( // ModelModeration is the current moderation // classifier reachable via [NewModerationModel]. ModelModeration = "mistral-moderation-2603" )
Moderation model ids.
const (
Provider = "Mistral"
)
Provider is the stable backend name for host-side attribution.
const (
RequestExtensionKey = "mistral/request"
)
Namespacing preserves provider-specific data without promoting it into the shared Core protocol or colliding with another provider.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat implements Mistral's native Chat Completions protocol, including structured thinking chunks and their multi-turn replay semantics.
func NewChat ¶
func NewChat(_ context.Context, config ChatConfig) (*Chat, error)
NewChat rejects an invalid provider binding before the first chat call.
type ChatConfig ¶
type ChatConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
}
ChatConfig binds provider access and defaults shared by every chat call.
func (ChatConfig) Validate ¶
func (c ChatConfig) Validate() error
type ChatRequestOptions ¶
type ChatRequestOptions struct {
ReasoningEffort ReasoningEffort `json:"reasoning_effort,omitempty"`
RandomSeed *int64 `json:"random_seed,omitempty"`
SafePrompt *bool `json:"safe_prompt,omitempty"`
PromptCacheKey string `json:"prompt_cache_key,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Guardrails []json.RawMessage `json:"guardrails,omitempty"`
}
ChatRequestOptions exposes Mistral-specific Chat Completions parameters that have no provider-neutral Core equivalent. Store it under RequestExtensionKey.
func (*ChatRequestOptions) UnmarshalJSON ¶
func (c *ChatRequestOptions) UnmarshalJSON(data []byte) error
func (ChatRequestOptions) Validate ¶
func (c ChatRequestOptions) Validate() error
type EmbeddingModel ¶
type EmbeddingModel = openai.EmbeddingModel
EmbeddingModel is the shared protocol type itself rather than a wrapper, so this provider adds no second public surface for callers to choose between.
func NewEmbeddingModel ¶
func NewEmbeddingModel(ctx context.Context, config EmbeddingModelConfig) (*EmbeddingModel, error)
NewEmbeddingModel rejects an invalid provider binding before the first embedding call.
type EmbeddingModelConfig ¶
type EmbeddingModelConfig struct {
APIKey string
DefaultOptions embedding.Options
BaseURL string
HTTPClient *http.Client
}
EmbeddingModelConfig binds provider access and defaults shared by every embedding call.
func (EmbeddingModelConfig) Validate ¶
func (e EmbeddingModelConfig) Validate() error
type ModerationModel ¶
type ModerationModel struct {
// contains filtered or unexported fields
}
ModerationModel wraps Mistral's /moderations endpoint. Mistral reports a custom category set (sexual / hate_and_discrimination / violence_and_threats / dangerous_and_criminal_content / selfharm / health / financial / law / pii). Category names are preserved exactly.
func NewModerationModel ¶
func NewModerationModel(_ context.Context, config ModerationModelConfig) (*ModerationModel, error)
NewModerationModel rejects an invalid provider binding before the first moderation call.
func (*ModerationModel) Call ¶
func (m *ModerationModel) Call(ctx context.Context, req *moderation.Request) (response *moderation.Response, err error)
type ModerationModelConfig ¶
type ModerationModelConfig struct {
APIKey string
DefaultOptions moderation.Options
BaseURL string
HTTPClient *http.Client
}
ModerationModelConfig binds provider access and defaults shared by every moderation call.
func (ModerationModelConfig) Validate ¶
func (m ModerationModelConfig) Validate() error
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort controls Mistral's native reasoning mode. The values are the six its chat endpoint documents as the reasoning_effort enum; empty asks the model for its own default.
const ( ReasoningEffortNone ReasoningEffort = "none" ReasoningEffortMinimal ReasoningEffort = "minimal" ReasoningEffortLow ReasoningEffort = "low" ReasoningEffortMedium ReasoningEffort = "medium" ReasoningEffortHigh ReasoningEffort = "high" ReasoningEffortXHigh ReasoningEffort = "xhigh" )
func (ReasoningEffort) Validate ¶
func (r ReasoningEffort) Validate() error