Skip to content

subiz/airouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Router

Go Reference Go Report Card License: MIT

AI Router is a lightweight Go client for the Subiz AI Proxy, providing a unified interface to multiple LLM providers including OpenAI, Google Gemini, and more.

Features

  • Unified API: Single interface for Chat Completion, Text Embedding, and Reranking across different providers.
  • Provider Agnostic: Switch between GPT-4, GPT-5, Gemini, and other models without changing your core logic.
  • Simplified Configuration: Easy initialization with a Subiz API key.

Installation

go get github.com/subiz/airouter

Getting Started

Initialization

Initialize the library with your Subiz API key:

import "github.com/subiz/airouter"

func init() {
    airouter.Init("YOUR_SUBIZ_API_KEY")
}

Usage Examples

1. Chat Completion

package main

import (
    "context"
    "fmt"
    "github.com/subiz/airouter"
)

func main() {
    airouter.Init("YOUR_SUBIZ_API_KEY")

    ctx := context.Background()
    output, _, err := airouter.Complete(ctx, airouter.CompletionInput{
        Model: airouter.Gpt_5_nano,
        ReasoningEffort: "low",
        Instruct: "Tell a short story about a brave dragon.",
    })

    if err != nil {
        panic(err)
    }

    fmt.Println(output) // The dragon’s name was Ember, and his light was not a blaze but a memory of dawn...
}

2. Text Embedding

package main

import (
    "context"
    "fmt"
    "github.com/subiz/airouter"
)

func main() {
    airouter.Init("YOUR_SUBIZ_API_KEY")

    vector, _, err := airouter.GetEmbedding(context.Background(), airouter.Text_embedding_3_small, "Hello world")
    if err != nil {
        panic(err)
    }

    fmt.Printf("Vector length: %d\n", len(vector))
    fmt.Println(vector[:5]) // Print first 5 dimensions
}

3. Rerank

package main

import (
    "context"
    "fmt"
    "github.com/subiz/airouter"
)

func main() {
    airouter.Init("YOUR_SUBIZ_API_KEY")

    records := []*airouter.RerankRecord{
        {Id: "1", Title: "Greeting", Content: "Xin chào thế giới"},
        {Id: "2", Title: "Farewell", Content: "Goodbye world"},
    }

    output, err := airouter.Rerank(context.Background(), "google", "hello", records)
    if err != nil {
        panic(err)
    }

    fmt.Println("Rerank results:", output)
}

Supported Models

Chat Completion

Provider Model Aliases
OpenAI gpt-4o, gpt-4o-mini, gpt-4.1, gpt-4.1-mini, gpt-4.1-nano, gpt-5, gpt-5-mini, gpt-5-nano
Google gemini-2.5-pro, gemini-2.5-flash, gemini-2.5-flash-lite, gemini-3.1-flash-lite-preview

Text Embedding

  • gemini-embedding-001
  • text-embedding-3-small
  • text-embedding-3-large
  • text-embedding-ada-002

Reranking

  • google (Powered by Google Vertex AI)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages