Skip to main content

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.

Overview

Mavera’s Responses API is compatible with OpenAI’s API shape. The 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

go get github.com/sashabaranov/go-openai

Configuration

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)
}
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.

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):
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)
    }
}
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.

Checking go-openai Compatibility

As of this writing, go-openai may support custom model names. Verify the latest go-openai README 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

SDKs Overview

Python, JavaScript, and REST options

Migrate OpenAI → Mavera

Base URL and persona_id

Quickstart: Chat

First request with cURL

API Reference

Responses API spec