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

# Go SDK

> Using the go-openai library with Mavera

## Overview

Mavera's Responses API is compatible with OpenAI's API shape. The [go-openai](https://github.com/sashabaranov/go-openai) library does not yet support the Responses API, so the REST approach with `net/http` is the primary method. You can still use go-openai for other OpenAI-compatible operations.

## Installation

```bash theme={"dark"}
go get github.com/sashabaranov/go-openai
```

## Configuration

```go theme={"dark"}
package main

import (
    "context"
    "fmt"
    "os"

    openai "github.com/sashabaranov/go-openai"
)

func main() {
    config := openai.DefaultConfig(os.Getenv("MAVERA_API_KEY"))
    config.BaseURL = "https://app.mavera.io/api/v1"

    client := openai.NewClientWithConfig(config)

    resp, err := client.CreateChatCompletion(
        context.Background(),
        openai.ChatCompletionRequest{
            Model: openai.GPT4,
            Messages: []openai.ChatCompletionMessage{
                {Role: openai.ChatMessageRoleUser, Content: "What matters most when choosing a product?"},
            },
        },
    )
    if err != nil {
        panic(err)
    }

    fmt.Println(resp.Choices[0].Message.Content)
}
```

<Info>
  **Model name:** The go-openai library may use `gpt-4` or similar. Mavera expects `mavera-1`. Check the library's `Model` constant or pass `"mavera-1"` as a string. Note that go-openai's `CreateChatCompletion` does not support the Responses API — use the REST approach below for full Mavera compatibility.
</Info>

## Passing persona\_id

The go-openai library doesn't expose `persona_id` on the request struct. You can:

1. **Use a forked or extended client** that adds Mavera fields
2. **Inject via a custom request** if the library supports extra fields
3. **Use the REST API directly** with `net/http` for full control

Example with REST (no SDK):

```go theme={"dark"}
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "os"
)

func main() {
    apiKey := os.Getenv("MAVERA_API_KEY")
    if apiKey == "" {
        panic("Set MAVERA_API_KEY")
    }

    body := map[string]interface{}{
        "model":      "mavera-1",
        "input":      "What matters most when choosing a product?",
        "persona_id": "YOUR_PERSONA_ID",
    }
    jsonBody, _ := json.Marshal(body)

    req, _ := http.NewRequest("POST", "https://app.mavera.io/api/v1/responses", bytes.NewReader(jsonBody))
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    var result struct {
        Output []struct {
            Content []struct {
                Text string `json:"text"`
            } `json:"content"`
        } `json:"output"`
        Usage struct {
            CreditsUsed int `json:"credits_used"`
        } `json:"usage"`
    }
    if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
        panic(err)
    }

    if len(result.Output) > 0 && len(result.Output[0].Content) > 0 {
        fmt.Println(result.Output[0].Content[0].Text)
        fmt.Printf("Credits used: %d\n", result.Usage.CreditsUsed)
    }
}
```

<Tip>
  For production, use a proper HTTP client, error handling, and avoid re-issuing requests. The REST approach gives you full control over `persona_id`, `input`, and other Mavera fields.
</Tip>

## Checking go-openai Compatibility

As of this writing, go-openai may support custom model names. Verify the latest [go-openai README](https://github.com/sashabaranov/go-openai) for:

* Custom `BaseURL` in config
* Custom model names (e.g. `"mavera-1"`)
* Any extension points for extra request fields

If the library adds support for extra request body fields, you can pass `persona_id` without using raw REST.

## See Also

<CardGroup cols={2}>
  <Card title="SDKs Overview" icon="plug" href="/sdks/overview">
    Python, JavaScript, and REST options
  </Card>

  <Card title="Migrate OpenAI → Mavera" icon="arrow-right" href="/cookbooks/migrate-openai-to-mavera">
    Base URL and persona\_id
  </Card>

  <Card title="Quickstart: Chat" icon="rocket" href="/quickstart-chat">
    First request with cURL
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/responses/create-a-response">
    Responses API spec
  </Card>
</CardGroup>
