> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Go SDK

> Use Yelu AI API with the official OpenAI Go SDK and a custom base URL.

The official OpenAI Go SDK supports a custom base URL and works with Yelu's OpenAI-compatible endpoints. The current v3 SDK requires Go 1.22 or later.

## Install

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
go get github.com/openai/openai-go/v3
```

## Configure the client

```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
package main

import (
	"os"

	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/option"
)

func newYeluClient() openai.Client {
	return openai.NewClient(
		option.WithAPIKey(os.Getenv("YELU_API_KEY")),
		option.WithBaseURL("https://api.yelu.ai/v1"),
	)
}
```

## Create a response

```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/responses"
)

func main() {
	client := newYeluClient()
	response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
		Model: "gpt-4o-mini",
		Input: responses.ResponseNewParamsInputUnion{
			OfString: openai.String("Give one practical API reliability tip."),
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(response.OutputText())
}
```

## Add a deadline

```go theme={"theme":{"light":"github-light","dark":"github-dark"}}
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

response, err := client.Responses.New(ctx, responses.ResponseNewParams{
	Model: "gpt-4o-mini",
	Input: responses.ResponseNewParamsInputUnion{
		OfString: openai.String("Explain exponential backoff."),
	},
})
if err != nil {
	return fmt.Errorf("create Yelu response: %w", err)
}
```

<Note>
  Pin the SDK major version in `go.mod` and review upstream release notes before upgrading. Yelu's HTTP contract is OpenAI-compatible, while generated SDK types can evolve independently.
</Note>

For endpoints or fields not represented by your installed SDK version, use Go's `net/http` package against the documented REST endpoint.
