01. Authenticate
How to authenticate with the Jinko API
In order to interact with the Jinko API, you'll first need to authenticate your application or script. Authentication is performed using an API key and a project ID, both obtainable from your Jinko project settings (see the Quick Start).
Authentication using environment variables
The recommended way to authenticate is to store your credentials in environment variables and let JinkoClient read them automatically:
export JINKO_API_KEY="your-api-key"
export JINKO_PROJECT_ID="your-project-id"
from jinko import JinkoClient
# Reads JINKO_API_KEY and JINKO_PROJECT_ID from the environment
client = JinkoClient()
result = client.auth_check()
print(result.status) # "authenticated" on success
Passing credentials explicitly
If you'd rather not rely on environment variables, pass the credentials directly when constructing the client:
from jinko import JinkoClient
client = JinkoClient(
api_key="your-api-key",
project_id="your-project-id",
)
client.auth_check()
Handling authentication errors
auth_check() raises AuthenticationError if the API key is invalid, and ConfigurationError if the credentials are missing or malformed (for instance not a valid UUID):
from jinko import JinkoClient, AuthenticationError, ConfigurationError
try:
client = JinkoClient()
client.auth_check()
except ConfigurationError as e:
print(f"Configuration issue: {e}")
except AuthenticationError as e:
print(f"Auth failed: {e}")