Environment:Togethercomputer Together python API Credentials
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Authentication |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
Environment variables required for Together AI SDK authentication and configuration.
Description
The Together AI Python SDK requires an API key for all API interactions. The key can be provided via the `TOGETHER_API_KEY` environment variable, passed directly to the client constructor, or (in Google Colab) stored as a notebook secret. Additional optional environment variables control the API base URL, logging verbosity, and deprecation banner display.
Usage
Use this environment whenever initializing a `Together()` or `AsyncTogether()` client. The `TOGETHER_API_KEY` is mandatory for all API workflows. Optional variables customize SDK behavior.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Network | HTTPS outbound access | To `api.together.xyz` or custom `TOGETHER_BASE_URL` |
| Runtime | Python 3.10+ | See Environment:Togethercomputer_Together_python_Python_SDK_Runtime |
Dependencies
No additional dependencies beyond the core SDK.
Credentials
The following environment variables are used by the SDK:
Required:
- `TOGETHER_API_KEY`: Together AI API key (Bearer token). Obtain from https://api.together.xyz/settings/api-keys
Optional:
- `TOGETHER_BASE_URL`: Override the default API endpoint (default: `https://api.together.xyz/v1`)
- `TOGETHER_LOG`: Set logging verbosity; valid values are `"debug"` or `"info"`
- `TOGETHER_NO_BANNER`: Set to any value to suppress the SDK v2.0 deprecation banner on import
Fine-Tuning Integrations (Optional):
- `wandb_api_key`: Weights & Biases API key, passed as a parameter to `fine_tuning.create()` (not an env var)
- `hf_api_token`: HuggingFace API token, passed as a parameter for HF model imports (not an env var)
Quick Install
# Set required API key
export TOGETHER_API_KEY="your-api-key-here"
# Optional: custom base URL
export TOGETHER_BASE_URL="https://api.together.xyz/v1"
# Optional: enable debug logging
export TOGETHER_LOG="debug"
# Optional: suppress deprecation banner
export TOGETHER_NO_BANNER=1
Code Evidence
API key resolution priority from `src/together/client.py:50-61`:
# get api key
if not api_key:
api_key = os.environ.get("TOGETHER_API_KEY")
if not api_key and "google.colab" in sys.modules:
api_key = get_google_colab_secret("TOGETHER_API_KEY")
if not api_key:
raise AuthenticationError(
"The api_key client option must be set either by passing api_key to the client or by setting the "
"TOGETHER_API_KEY environment variable"
)
Base URL fallback from `src/together/client.py:64-68`:
if not base_url:
base_url = os.environ.get("TOGETHER_BASE_URL")
if not base_url:
base_url = BASE_URL # "https://api.together.xyz/v1"
Logging level from `src/together/utils/_log.py:14,19-25`:
TOGETHER_LOG = os.environ.get("TOGETHER_LOG")
def _console_log_level() -> str | None:
if together.log in ["debug", "info"]:
return together.log
elif TOGETHER_LOG in ["debug", "info"]:
return TOGETHER_LOG
else:
return None
Banner suppression from `src/together/__init__.py:24`:
if not os.environ.get("TOGETHER_NO_BANNER"):
# ... display deprecation banner
Missing API key error message from `src/together/constants.py:34-36`:
MISSING_API_KEY_MESSAGE = """TOGETHER_API_KEY not found.
Please set it as an environment variable or set it as together.api_key
Find your TOGETHER_API_KEY at https://api.together.xyz/settings/api-keys"""
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `AuthenticationError: The api_key client option must be set...` | No API key found | Set `TOGETHER_API_KEY` env var or pass `api_key=` to `Together()` |
| `TOGETHER_API_KEY not found` | Legacy code path; no API key | Set `TOGETHER_API_KEY` or use `together.api_key = "..."` (deprecated) |
| `AuthenticationError: This job would exceed your free trial credits` | Insufficient account credits | Upgrade to paid account at Settings > Billing on api.together.ai |
| Colab: `NotebookAccessError` | Colab secret exists but access disabled | Enable notebook access for the `TOGETHER_API_KEY` secret in Colab |
Compatibility Notes
- API Key Priority: Explicit `api_key` parameter > `TOGETHER_API_KEY` env var > Google Colab secret.
- Google Colab: SDK auto-detects Colab and checks notebook secrets. Both `NotebookAccessError` and `SecretNotFoundError` are handled gracefully.
- Legacy `together.api_key`: Module-level variable is deprecated; use the environment variable instead.
- Bearer Token: API key is sent as `Authorization: Bearer {key}` header.