Home / Market / go-mistral

go-mistral

Unofficial 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.WithRequestEdito

skill★ 00 dlclawhubMIT-0Install in CosmosUpstream Source

Documentation & Preview

go-mistral: setup and reference

Requirements

Install

go get github.com/psyb0t/go-mistral

The package name is mistral:

import "github.com/psyb0t/go-mistral"

Auth

Mistral AI takes Authorization: Bearer <api key>. Add the header with a RequestEditorFn: for every request through mistral.WithRequestEditorFn, or for one call by passing it as the last argument of that method.

Client options

| Option | Effect | |---|---| | mistral.WithRequestEditorFn(fn) | Runs fn on every request, used for the auth header. | | mistral.WithHTTPClient(doer) | Replaces http.DefaultClient, for timeouts or transport settings. | | mistral.WithBaseURL(url) | Overrides the server passed to the constructor. |

Base URL: https://api.mistral.ai. Paths in the spec already start with /v1.

Calling operations

Method names come from the spec's operation IDs. Each operation X has:

Some operations:

| Method | Request | |---|---| | ListModelsV1ModelsGetWithResponse(ctx, *ListModelsV1ModelsGetParams) | List models. | | ChatCompletionV1ChatCompletionsPostWithResponse(ctx, ChatCompletionRequest) | Chat completion. | | EmbeddingsV1EmbeddingsPostWithResponse(ctx, EmbeddingsV1EmbeddingsPostJSONRequestBody) | Embeddings. |

Run go doc github.com/psyb0t/go-mistral ClientWithResponsesInterface to find the rest. Do not guess a method name.

Union types

Fields the spec types as one of several shapes are structs with From<Variant>, As<Variant> and Merge<Variant> methods:

Run go doc github.com/psyb0t/go-mistral <UnionType> for the exact variant names of any other union.

Responses

Every XResponse has:

Other error statuses have no typed field; read Body. A method returns a non-nil error only for transport failures and bodies that do not decode.

Regenerating

client.gen.go is generated. For changes to the client itself, see AGENTS.md in the repository.