Authentication Methods
The Garnet API Go SDK supports three distinct authentication methods, each designed for specific use cases:User Tokens
OAuth 2.0 JWT tokens for user authentication via Auth0
Agent Tokens
API key tokens for agent-specific operations
Project Tokens
API tokens for programmatic access with custom permissions
Token Type Enum
The SDK defines aTokenType enum to distinguish between authentication methods:
client/client.go
How Authentication Works
When you create a client or configure authentication, the SDK automatically sets the appropriate HTTP headers based on the token type:| Token Type | HTTP Header | Format |
|---|---|---|
| User Token | Authorization | Bearer <token> |
| Agent Token | X-Agent-Token | <token> |
| Project Token | X-Project-Token | <token> |
The SDK automatically handles header formatting. User tokens are prefixed with “Bearer ” if not already present.
Client Initialization
The basic client initialization assumes a user token:Switching Token Types
You can reconfigure an existing client to use different token types:The
With* methods return a cloned client, leaving the original unchanged.Manual Token Configuration
For advanced use cases, you can set both token and type manually:client/client.go
Security Best Practices
Use Appropriate Token Types
- User tokens for interactive applications
- Agent tokens for agent operations only
- Project tokens for automated workflows and CI/CD
Error Handling
Authentication failures return 401 Unauthorized errors:Next Steps
User Tokens
Learn about OAuth 2.0 user authentication
Agent Tokens
Configure agent authentication
Project Tokens
Set up programmatic access
