Skip to content

mistral-client

HTTP client for Mistral AI written in Go.

Logo

Requirements

  • Go 1.25 or higher

Installation

go get github.com/thomas-marquis/mistral-client

Features

Basic features:

What makes a difference:

  • Caching: Cache responses to avoid unnecessary repeated API calls (e.g. for local development runs).
  • MLflow integration: Get your prompts from MLflow Prompt Registry instead of writing them in your code.

Coming soon:

  • Fake models: Use fake models for local development and testing.

Getting Started

To start using the Mistral client, you first need to create an instance of the client with your API key:

import "github.com/thomas-marquis/mistral-client/mistral"

client := mistral.New(apiKey)

You can also customize the client with various options:

client := mistral.New(apiKey,
    mistral.WithClientTimeout(60*time.Second),
    mistral.WithRetry(4, 1*time.Second, 3*time.Second),
)

Basic Usage

Chat Completion

req := mistral.NewChatCompletionRequest("mistral-small-latest", []mistral.ChatMessage{
    mistral.NewUserMessageFromString("Hello! How are you today?"),
})

res, err := client.ChatCompletion(context.Background(), req)
if err != nil {
    log.Fatal(err)
}

fmt.Println(res.AssistantMessage().Content().String())

Tool Calling

tools := []mistral.Tool{
    mistral.NewTool("get_weather", "Get the weather for a location", mistral.PropertyDefinition{
        Type: "object",
        Properties: map[string]mistral.PropertyDefinition{
            "location": {Type: "string", Description: "The city and state, e.g. San Francisco, CA"},
        },
    }),
}

req := mistral.NewChatCompletionRequest("mistral-small-latest", []mistral.ChatMessage{
    mistral.NewUserMessageFromString("What's the weather in Paris?"),
}, mistral.WithTools(tools))

res, err := client.ChatCompletion(context.Background(), req)

Embeddings

req := mistral.NewEmbeddingRequest("mistral-embed", []string{"Mistral AI is awesome!"})

res, err := client.Embeddings(context.Background(), req)
if err != nil {
    log.Fatal(err)
}

for _, vector := range res.Embeddings() {
    fmt.Println(vector)
}

Examples

You can find more detailed examples in the examples folder.

Interacting with Mistral models:

Model discovery:

Specific features: