For the complete documentation index, see llms.txt. This page is also available as Markdown.

Authenticate with the Python SDK

The Python SDK accepts an API key three ways. Pick whichever fits your runtime - they all end up at the same Roboflow object.

Set ROBOFLOW_API_KEY in your shell or CI environment:

export ROBOFLOW_API_KEY=rf_xxxxx
import roboflow

rf = roboflow.Roboflow()  # picks up ROBOFLOW_API_KEY

This is the cleanest path for scripts, notebooks, and AI coding agents - no interactive prompts and no on-disk state.

Option 2: Pass the key explicitly

import roboflow

rf = roboflow.Roboflow(api_key="rf_xxxxx")

Useful when you have multiple keys for multiple workspaces in the same process.

Option 3: Interactive login

import roboflow

roboflow.login()

Opens an authentication URL in the browser, prompts for a token, and saves credentials to ~/.config/roboflow/config.json. Subsequent Roboflow() calls (with no arguments) read from that file.

To re-authenticate against a different account or refresh the token:

The CLI's roboflow login writes to the same on-disk location, so once either tool authenticates, the other picks up the credentials too.

Where to find your API key

In the Roboflow web app, navigate to Settings → API Key. Each workspace has its own key - the key you use determines the workspace your code authenticates against.

For scoped API keys (limit a key to specific resources or operations), see the Authentication section.

Override the config location

If you need credentials stored somewhere other than ~/.config/roboflow/, set ROBOFLOW_CONFIG_DIR:

See Environment Variables for the full list of variables the SDK and CLI respect.

Last updated

Was this helpful?