Authentication Resource
API methods for authentication operations.
Methods
token
Exchange API Key for Access Token Exchange an API key for a JWT access token.
This endpoint accepts an API key and tenant identifier, validates them against the authentication service, and returns a JWT access token that can be used for subsequent authenticated requests.
The returned access token should be included in the Authorization header as a Bearer token for all authenticated API calls.
Method: POST
Path: /auth/token
response = client.authentication.token()
Parameters
Responses
200 - Successful Response
- Content-Type:
application/json - Schema:
TokenResponse
422 - Validation Error
- Content-Type:
application/json - Schema:
HTTPValidationError
Usage Examples
Here's a complete example using the token method:
import asyncio
from credoai import
async def main():
# Initialize client
client = (
base_url="https://api.credo.ai",
api_key="test_password-your-api-key"
)
try:
# Exchange API Key for Access Token
response = await client.authentication.token()
print(f"Success: {response}")
except Exception as e:
print(f"Error: {e}")
finally:
await client.close()
# Run the example
asyncio.run(main())
Error Handling
All methods in this resource can raise the following exceptions:
ValidationError- Invalid request dataAPIError- Server-side errorsAuthenticationError- Invalid or missing API keyNotFoundError- Resource not found (404)RateLimitError- Too many requests
from credoai.errors import APIError, ValidationError
try:
response = client.authentication.token()
except ValidationError as e:
print(f"Invalid request: {e}")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")