---
sidebar_position: 3
---

# Quickstart: LangChainGo with Mistral

Dive right into executing your first program utilizing LangChainGo in tandem with the [Mistral Platform](https://mistral.ai/).

## Pre-requisites

1. **Mistral API Key**: Sign up on [Mistral](https://mistral.ai/) and retrieve your API key.
2. **Go**: [Download and install Go](https://go.dev/doc/install).

## Steps

1. **Set up your Mistral API Key**: Before interacting with the Mistral API, ensure that you've set up your API key. Typically, this is done by setting an environment variable. In your terminal, run the command:
```shell
   export MISTRAL_API_KEY=your_mistral_api_key_here
```

2. Run the Example: Execute the following command:

```shell
go run github.com/tmc/langchaingo/examples/mistral-completion-example@main
```

Anticipate an output similar to the one below:

```txt
The first man to walk on the moon was Neil Armstrong on July 20, 1969. He made this historic step during the Apollo 11 mission. Armstrong's famous quote upon setting foot on the lunar surface was, "That's one small step for man, one giant leap for mankind."
The first human to go to space was Yuri Gagarin, a Soviet cosmonaut. He completed an orbit around the Earth in the spacecraft Vostok 1 on April 12, 1961. This historic event marked the beginning of human space exploration.
```

Congratulations! You've successfully built and executed your first LangChainGo LLM-backed program using Mistral's cloud-based inference.


Here is the entire program (from [mistral-chat-example](https://github.com/tmc/langchaingo/blob/main/examples/mistral-chat-example/mistral_chat_example.go)).

```go
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/tmc/langchaingo/llms"
	"github.com/tmc/langchaingo/llms/mistral"
)

func main() {
	llm, err := mistral.New()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	completion, err := llms.GenerateFromSinglePrompt(ctx, llm, "Who was the first man to go to space?",
		llms.WithTemperature(0.2),
		llms.WithModel("mistral-small-latest"),
	)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("\n" + completion)
}
```