routerbase

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 9 Imported by: 0

README

RouterBase Go Client

RouterBase provides an OpenAI-compatible API at https://routerbase.com/v1. This Go module is a small starter client for chat completions and model listing.

Install

go get github.com/RouterBase/routerbase-examples/packages/go-routerbase

Usage

package main

import (
	"context"
	"fmt"
	"os"

	routerbase "github.com/RouterBase/routerbase-examples/packages/go-routerbase"
)

func main() {
	client := routerbase.NewClient(os.Getenv("ROUTERBASE_API_KEY"))

	resp, err := client.ChatCompletion(context.Background(), routerbase.ChatCompletionRequest{
		Messages: []routerbase.Message{
			{Role: "user", Content: "Explain RouterBase in one sentence."},
		},
	})
	if err != nil {
		panic(err)
	}

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

Documentation

Index

Constants

View Source
const (
	BaseURL      = "https://routerbase.com/v1"
	DefaultModel = "google/gemini-2.5-flash"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletionRequest

type ChatCompletionRequest struct {
	Model       string    `json:"model,omitempty"`
	Messages    []Message `json:"messages"`
	Temperature *float64  `json:"temperature,omitempty"`
	MaxTokens   *int      `json:"max_tokens,omitempty"`
}

type ChatCompletionResponse

type ChatCompletionResponse struct {
	ID      string `json:"id,omitempty"`
	Object  string `json:"object,omitempty"`
	Choices []struct {
		Index   int     `json:"index,omitempty"`
		Message Message `json:"message"`
	} `json:"choices"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, options ...Option) *Client

func (*Client) ChatCompletion

func (client *Client) ChatCompletion(ctx context.Context, request ChatCompletionRequest) (*ChatCompletionResponse, error)

func (*Client) ListModels

func (client *Client) ListModels(ctx context.Context) (*ModelsResponse, error)

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type Model

type Model struct {
	ID      string `json:"id"`
	Object  string `json:"object,omitempty"`
	Created int64  `json:"created,omitempty"`
	OwnedBy string `json:"owned_by,omitempty"`
}

type ModelsResponse

type ModelsResponse struct {
	Data []Model `json:"data"`
}

type Option

type Option func(*Client)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

Directories

Path Synopsis
examples
chat command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL