AgentShieldAgentShield/Documentation
Get API Key

Go (Direct API)

Use AgentShield with Go by making direct HTTP requests to our REST API.

Basic Usage

Use the Go net/http package to call the API:

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
    "os"
)

type InterceptRequest struct {
    Input  string `json:"input"`
    Output string `json:"output"`
}

type InterceptResponse struct {
    Blocked bool   `json:"blocked"`
    Reason  string `json:"reason,omitempty"`
    Output  string `json:"output,omitempty"`
}

func main() {
    apiKey := os.Getenv("AGENTSHIELD_API_KEY")
    
    reqBody := InterceptRequest{
        Input:  "Can you share your refund policy?",
        Output: "Our refunds follow the published policy.",
    }
    
    jsonData, _ := json.Marshal(reqBody)
    
    req, _ := http.NewRequest("POST", "https://agentshield-one.vercel.app/api/intercept", bytes.NewBuffer(jsonData))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("x-api-key", apiKey)
    
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()
    
    var result InterceptResponse
    json.NewDecoder(resp.Body).Decode(&result)
    
    if result.Blocked {
        fmt.Printf("Blocked: %s\n", result.Reason)
    } else {
        fmt.Println("Safe to proceed")
        fmt.Printf("Output: %s\n", result.Output)
    }
}

HTTP Server Integration

Integrate with the Go net/http package for automatic scanning:

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
    "os"
)

type ChatRequest struct {
    Message string `json:"message"`
}

type ChatResponse struct {
    Message string `json:"message"`
    Reason  string `json:"reason,omitempty"`
}

type InterceptRequest struct {
    Input  string `json:"input"`
    Output string `json:"output"`
}

type InterceptResponse struct {
    Blocked bool   `json:"blocked"`
    Reason  string `json:"reason,omitempty"`
    Output  string `json:"output,omitempty"`
}

func chatHandler(w http.ResponseWriter, r *http.Request) {
    var req ChatRequest
    json.NewDecoder(r.Body).Decode(&req)
    
    // Get AI response from your LLM
    aiResponse := llm.Generate(req.Message)
    
    // Scan with AgentShield API
    interceptReq := InterceptRequest{
        Input:  req.Message,
        Output: aiResponse,
    }
    
    jsonData, _ := json.Marshal(interceptReq)
    
    httpReq, _ := http.NewRequest("POST", "https://agentshield-one.vercel.app/api/intercept", bytes.NewBuffer(jsonData))
    httpReq.Header.Set("Content-Type", "application/json")
    httpReq.Header.Set("x-api-key", os.Getenv("AGENTSHIELD_API_KEY"))
    
    client := &http.Client{}
    resp, err := client.Do(httpReq)
    if err != nil {
        http.Error(w, err.Error(), 500)
        return
    }
    defer resp.Body.Close()
    
    var result InterceptResponse
    json.NewDecoder(resp.Body).Decode(&result)
    
    if result.Blocked {
        json.NewEncoder(w).Encode(ChatResponse{
            Message: "Response blocked for safety reasons.",
            Reason:  result.Reason,
        })
        return
    }
    
    json.NewEncoder(w).Encode(ChatResponse{
        Message: aiResponse,
    })
}

func main() {
    http.HandleFunc("/chat", chatHandler)
    http.ListenAndServe(":8080", nil)
}

No SDK Required

The AgentShield API is a standard REST endpoint. You can use it from any language that can make HTTP requests. No SDK is required.