Authentication
SDK Authentication
All Silent Witness SDKs use API key authentication. You configure your API key once when initializing your SDK client, and the SDK handles all authentication automatically.
API Key Authentication
Configure your API key when creating your SDK client
Automatic Header Management
SDKs automatically include authentication in all requests
Configuring Authentication
Configure your API key when initializing your SDK client:
- Go
- TypeScript
import "github.com/silentwitness/go-sdk"
// Option 1: Package-level configuration
silentwitness.Key = "sk-your-api-key-here"
// Option 2: Client instance configuration
client := silentwitness.NewClient(silentwitness.Config{
APIKey: "sk-your-api-key-here",
})
defer client.Close()
import { setApiKey, SilentWitnessClient } from "@silentwitness/typescript-sdk";
// Option 1: Package-level configuration
setApiKey("sk-your-api-key-here");
// Option 2: Client instance configuration
const client = new SilentWitnessClient({
apiKey: "sk-your-api-key-here",
});
API keys start with sk- and are 64 characters long. Keep your API key secure and never expose it in client-side code.
Environment Variables
For production applications, store your API key in environment variables:
- Go
- TypeScript
import (
"os"
"github.com/silentwitness/go-sdk"
)
client := silentwitness.NewClient(silentwitness.Config{
APIKey: os.Getenv("SILENT_WITNESS_API_KEY"),
})
import { SilentWitnessClient } from "@silentwitness/typescript-sdk";
const client = new SilentWitnessClient({
apiKey: process.env.SILENT_WITNESS_API_KEY,
});
Getting an API Key
Log into your Silent Witness Console dashboard
Navigate to API keys section and create a new key
Store your API key securely in environment variables
Upload a test file to verify your key works
API Key Management
Account Association
API keys are associated with your account and all usage is billed to your account:
- Cases created via API keys are associated with your account
- Invoices are generated automatically for case creation and usage
- All usage counts toward your subscription plan limits
- Case history shows both user-created and API key-created cases
Scopes
API keys can be restricted to specific scopes:
read- Read-only access to SDK methodswrite- Full read/write access to all methodsadmin- Administrative operations
Rate Limits
Each API key has rate limiting applied:
- Default: 1000 requests per hour
- SDK Handling: SDKs automatically handle rate limit errors with retry logic
- Custom: Contact support for higher limits
Security Best Practices
Keep your API key secure
- Never commit API keys to version control
- Use environment variables in production
- Rotate keys regularly
- Monitor key usage
Authentication Errors
If authentication fails, SDKs will return language-specific errors:
- Go
- TypeScript
response, err := client.Files.Upload(ctx, &silentwitness.UploadFileRequest{
Content: []byte("test"),
Filename: silentwitness.String("test.txt"),
})
if err != nil {
// Check for authentication error
if strings.Contains(err.Error(), "UNAUTHENTICATED") {
log.Fatal("Invalid API key")
}
}
try {
const response = await client.files.upload({
content: new Uint8Array([116, 101, 115, 116]), // "test"
filename: "test.txt"
});
} catch (error) {
if (error.code === 'UNAUTHENTICATED') {
console.error('Invalid API key');
}
}
Testing Authentication
Use the file upload method to test your authentication:
- Go
- TypeScript
package main
import (
"context"
"log"
"github.com/silentwitness/go-sdk"
)
func main() {
client := silentwitness.NewClient(silentwitness.Config{
APIKey: "sk-your-api-key-here",
})
defer client.Close()
fileBytes := []byte("test file content")
response, err := client.Files.Upload(context.Background(),
&silentwitness.UploadFileRequest{
Content: fileBytes,
Filename: silentwitness.String("test.txt"),
Purpose: silentwitness.String("crash_analysis"),
})
if err != nil {
log.Fatalf("Authentication failed: %v", err)
}
log.Printf("Success: File uploaded with ID %s", response.FileId)
}
import { SilentWitnessClient } from "@silentwitness/typescript-sdk";
const client = new SilentWitnessClient({
apiKey: "sk-your-api-key-here",
});
async function testAuth() {
try {
const response = await client.files.upload({
content: new Uint8Array([116, 101, 115, 116]), // "test"
filename: "test.txt"
});
console.log("Success:", response.message);
} catch (error) {
console.error("Authentication failed:", error);
}
}
testAuth();