API Reference
Simple Go integration with syntax highlighting for the Siloam AI API.
Complete Go integration with proper syntax highlighting:
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
// Log an AI interaction
payload := map[string]interface{
"model": "gpt-4",
"input": "What is machine learning?",
"output": "Machine learning is a subset of AI...",
"sessionId": "session-123",
"tokens": 150,
"cost": 0.003,
}
data, _ := json.Marshal(payload)
req, _ := http.NewRequest("POST", "https://demo.siloam.ai/api/log", bytes.NewBuffer(data))
req.Header.Set("Authorization", "Bearer "+os.Getenv("SILOAM_API_TOKEN"))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
var result map[string]string
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println("Log ID:", result["id"])
}