Account and authentication

This guide explains how to set up your distil labs account and authenticate against the platform API.

Registration

You can register a new account here by selecting “Sign up” at the bottom of the form.

Obtaining your API token

Once your account is set up, you need to generate an API token for programmatic access:

1import os
2import json
3import requests
4
5DISTIL_USERNAME = os.environ.get("DISTIL_USERNAME", "")
6DISTIL_PASSWORD = os.environ.get("DISTIL_PASSWORD", "")
7
8if not DISTIL_USERNAME or not DISTIL_PASSWORD:
9 raise ValueError("DISTIL_USERNAME and DISTIL_PASSWORD must be set")
10
11
12def distil_bearer_token() -> str:
13 """
14 Get an authentication token from the distil labs API
15
16 Returns:
17 str: Authentication token for API requests
18 """
19 response = requests.post(
20 "https://cognito-idp.eu-central-1.amazonaws.com",
21 headers={
22 "X-Amz-Target": "AWSCognitoIdentityProviderService.InitiateAuth",
23 "Content-Type": "application/x-amz-json-1.1",
24 },
25 data=json.dumps({
26 "AuthParameters": {"USERNAME": DISTIL_USERNAME, "PASSWORD": DISTIL_PASSWORD},
27 "AuthFlow": "USER_PASSWORD_AUTH",
28 "ClientId": "4569nvlkn8dm0iedo54nbta6fd",
29 })
30 )
31 response.raise_for_status()
32 return response.json()["AuthenticationResult"]["AccessToken"]

Using your API token

Once you have your token, use it in the Authorization header for all API requests:

1# sample request to list models (should return an empty list for now)
2response = requests.get(
3 "https://api.distillabs.ai/models",
4 headers={"Authorization": f"Bearer {distil_bearer_token()}"}
5)
6print(response.json())

The tokens are valid for 1 hour so your code should handle re-authentication when needed.

Troubleshooting authentication issues

  • 401 Unauthorized Error: Check that your username and password are correct.
  • 403 Forbidden Error: This typically means your token has expired. Generate a new token.
  • Connection Errors: Ensure you have proper network connectivity to the API endpoints.

For any account or authentication issues, please contact contact@distillabs.ai.