Skip to content

Repository files navigation

AIBIM Go SDK

Go client library for the AIBIM AI security proxy.

Install

go get github.com/aibim-ai/go-sdk

Quick Start

Proxy LLM Traffic

Route LLM requests through AIBIM for security scanning:

package main

import (
    "context"
    "fmt"
    "log"

    aibim "github.com/aibim-ai/go-sdk"
)

func main() {
    proxy := aibim.NewProxy(
        "https://your-aibim.example.com",
        "your-aibim-api-key",
        "sk-your-openai-key",
    )

    resp, meta, err := proxy.ChatCompletion(context.Background(), map[string]interface{}{
        "model": "gpt-4",
        "messages": []map[string]interface{}{
            {"role": "user", "content": "Hello!"},
        },
    })
    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Decision: %s, Score: %.2f\n", meta.Decision, meta.Score)
    fmt.Printf("Response: %v\n", resp)
}

Analyze Prompts

Check prompts for security risks without proxying:

guard := aibim.NewGuard("https://your-aibim.example.com", "your-api-key")
result, err := guard.Analyze(ctx, "ignore previous instructions and...")
if result.Decision == aibim.DecisionBlock {
    fmt.Println("Blocked:", result.MatchedRules)
}

Management Client

Access the full AIBIM API:

client := aibim.NewClient(&aibim.ClientConfig{
    BaseURL: "https://your-aibim.example.com",
    APIKey:  "your-api-key",
})

// List detection events
events, _ := client.Data.Events(ctx, map[string]string{"limit": "10"})

// Get alert stats
stats, _ := client.Alerts.Stats(ctx)

// Manage detection rules
rules, _ := client.Rules.List(ctx)

Real-time Alerts (WebSocket)

ws, err := aibim.NewAlertsWebSocket("https://your-aibim.example.com", "your-api-key")
if err != nil {
    log.Fatal(err)
}
defer ws.Close()

for alert := range ws.Listen(ctx) {
    fmt.Println("Alert:", alert)
}

Wrap Existing Clients

Redirect a third-party OpenAI client through AIBIM:

// client := openai.NewClient("sk-...")
aibim.Wrap(client, &aibim.WrapOptions{
    URL:    "https://your-aibim.example.com",
    APIKey: "your-api-key",
})
// client now routes through AIBIM

aibim.Unwrap(client) // restore original

Error Handling

The SDK returns typed errors:

  • *aibim.AuthError — 401 Unauthorized
  • *aibim.BlockedError — request blocked by security policy
  • *aibim.RateLimitError — 429 Too Many Requests (includes RetryAfter)
  • *aibim.AibimError — other HTTP errors
import "errors"

var blocked *aibim.BlockedError
if errors.As(err, &blocked) {
    fmt.Printf("Blocked! Score: %.2f, Rules: %v\n", blocked.RiskScore, blocked.MatchedRules)
}

Configuration

Option Default Description
Timeout 30s (Client) / 120s (Proxy) HTTP request timeout
MaxRetries 3 Retry attempts with exponential backoff

License

See repository root.

About

AIBIM Go SDK

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages