Go client library for the AIBIM AI security proxy.
go get github.com/aibim-ai/go-sdkRoute 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)
}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)
}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)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)
}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 originalThe 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)
}| Option | Default | Description |
|---|---|---|
| Timeout | 30s (Client) / 120s (Proxy) | HTTP request timeout |
| MaxRetries | 3 | Retry attempts with exponential backoff |
See repository root.