Install
openclaw skills install @psyb0t/go-mistralUnofficial Go client for the Mistral AI REST API, generated with oapi-codegen. mistral.NewClientWithResponses("https://api.mistral.ai", opts...) from github.com/psyb0t/go-mistral returns a *mistral.ClientWithResponses with one typed method per endpoint, named after the spec's operation IDs (ChatCompletionV1ChatCompletionsPostWithResponse, ListModelsV1ModelsGetWithResponse, EmbeddingsV1EmbeddingsPostWithResponse and more). Auth is a bearer API key set through mistral.WithRequestEditorFn; union fields such as message content use From... and As... methods. Use when Go code needs to call Mistral AI or already imports go-mistral.
openclaw skills install @psyb0t/go-mistralTyped Go client for the Mistral AI API. Every endpoint in Mistral AI's OpenAPI document is a method on ClientWithResponses.
For install, client options, more operations, union types and response handling, see references/setup.md.
MISTRAL_API_KEY. Never hardcode it, commit it or log it, and never print request headers.https://api.mistral.ai. Prompts and files you send are processed by Mistral AI.github.com/psyb0t/go-mistral....WithResponse methods read the whole body; a streamed reply needs your own SSE reader on the *http.Response from the raw Client.import (
"context"
"fmt"
"net/http"
"os"
"github.com/psyb0t/go-mistral"
)
auth := mistral.WithRequestEditorFn(
func(_ context.Context, req *http.Request) error {
req.Header.Set(
"Authorization",
"Bearer "+os.Getenv("MISTRAL_API_KEY"),
)
return nil
},
)
client, err := mistral.NewClientWithResponses("https://api.mistral.ai", auth)
if err != nil {
return err
}
A chat completion. Message content and the messages list are union types, built with From... methods:
var content mistral.UserMessage_Content
if err := content.FromUserMessageContent0("hello"); err != nil {
return err
}
role := mistral.UserMessageRoleUser
var message mistral.ChatCompletionRequest_Messages_Item
err = message.FromUserMessage(
mistral.UserMessage{Content: &content, Role: &role},
)
if err != nil {
return err
}
res, err := client.ChatCompletionV1ChatCompletionsPostWithResponse(
ctx,
mistral.ChatCompletionRequest{
Model: "<model-id>",
Messages: []mistral.ChatCompletionRequest_Messages_Item{message},
},
)
if err != nil {
return err // transport failure
}
if res.JSON200 == nil {
return fmt.Errorf("mistral: status %d", res.StatusCode())
}
for _, choice := range res.JSON200.Choices {
if choice.Message.Content == nil {
continue
}
text, err := choice.Message.Content.AsAssistantMessageContent0()
if err == nil {
fmt.Println(text)
}
}
Listing models: client.ListModelsV1ModelsGetWithResponse(ctx, &mistral.ListModelsV1ModelsGetParams{}), with the result in res.JSON200.Data.
A method returns an error only when the request could not be sent or the body could not be decoded. An API error is a normal response: check StatusCode(); a 422 also fills JSON422, an *HTTPValidationError, and every status leaves the raw reply in Body.