---
sidebar_position: 2
---

# Quickstart: LangChainGo with OpenAI

Dive right into executing your first program utilizing LangChainGo in tandem with [OpenAI](https://openai.com/). OpenAI's GPT models are renowned for their proficiency and expansive capabilities.

## Pre-requisites

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

## Steps

1. **Set up your OpenAI API Key**: Before interacting with the OpenAI 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 OPENAI_API_KEY=your_openai_api_key_here
```

2. Run the Example: Execute the following command:

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

Anticipate an output similar to the one below:

```shell
The first man to walk on the moon was Neil
```

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


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

```go
package main

import (
	"context"
	"fmt"
	"log"

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

func main() {
	llm, err := openai.New()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	completion, err := llm.Call(ctx, "The first man to walk on the moon",
		llms.WithTemperature(0.8),
		llms.WithStopWords([]string{"Armstrong"}),
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(completion)
}
```


