Skip to main content

Go SDK

Use the popular go-openai SDK with GonkaGate. Fully compatible with the OpenAI API.

Community SDK

We recommend using the sashabaranov/go-openai SDK, the most popular Go client for OpenAI-compatible APIs.

github.com/sashabaranov/go-openai

For API keys, base URL, and your first request, start with the Quickstart guide .

Installation

Install the go-openai SDK using go get:

terminal
go get github.com/sashabaranov/go-openai

Configuration

Configure the client to use GonkaGate's API endpoint:

config.go
package main

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

func main() {
    config := openai.DefaultConfig("gp-your-api-key")
    config.BaseURL = "https://api.gonkagate.com/v1"

    client := openai.NewClientWithConfig(config)
}

Basic Usage

Make your first chat completion request:

basic_usage.go
package main

import (
    "context"
    "fmt"
    "log"

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

func main() {
    config := openai.DefaultConfig("gp-your-api-key")
    config.BaseURL = "https://api.gonkagate.com/v1"

    client := openai.NewClientWithConfig(config)

    resp, err := client.CreateChatCompletion(
        context.Background(),
        openai.ChatCompletionRequest{
            Model: "qwen/qwen3-235b-a22b-instruct-2507-fp8",
            Messages: []openai.ChatCompletionMessage{
                {
                    Role:    openai.ChatMessageRoleSystem,
                    Content: "You are a helpful assistant.",
                },
                {
                    Role:    openai.ChatMessageRoleUser,
                    Content: "Hello, how are you?",
                },
            },
            Temperature: 0.7,
            MaxTokens:   1000,
        },
    )

    if err != nil {
        log.Fatalf("ChatCompletion error: %v", err)
    }

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

Context & Cancellation

Use Go contexts for timeouts and cancellation:

context.go
package main

import (
    "context"
    "fmt"
    "log"
    "time"

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

func main() {
    config := openai.DefaultConfig("gp-your-api-key")
    config.BaseURL = "https://api.gonkagate.com/v1"

    client := openai.NewClientWithConfig(config)

    // Create context with timeout
    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()

    resp, err := client.CreateChatCompletion(
        ctx,
        openai.ChatCompletionRequest{
            Model: "qwen/qwen3-235b-a22b-instruct-2507-fp8",
            Messages: []openai.ChatCompletionMessage{
                {Role: openai.ChatMessageRoleUser, Content: "Hello!"},
            },
        },
    )

    if err != nil {
        if ctx.Err() == context.DeadlineExceeded {
            log.Fatal("Request timed out")
        }
        log.Fatalf("Error: %v", err)
    }

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

Language-specific notes

A few Go-specific tips before you ship:

  • Reuse a shared http.Client and set timeouts.
  • Use context.Context for cancellations and deadlines.
  • Implement retries for 429/503 responses.

See Streaming and Error handling for real-time responses and retry guidance.

Was this page helpful?