ArenaClient¶
The main client for interacting with the Arena platform. Handles authentication, environment management, experiment submission, and agent deployment.
- class agilerl.arena.client.ArenaClient(*, api_key: str | None = None, org_key: str | None = None, external_user_id: str | None = None, request_timeout: int = 30, upload_timeout: int = 300, verbose: bool = True)¶
Client for the Arena RLOps platform.
Handles authentication, environment management, and training job submission.
Authentication is resolved in priority order:
org_key plus external_user_id (constructor or
ARENA_ORG_KEY/ARENA_EXTERNAL_USER_ID). SendsAuthorization: Bearer <org key>andX-External-User-Id.api_key constructor argument
ARENA_API_KEYenvironment variableStored OAuth credentials from
~/.arena/credentials.jsonInteractive
login()(device authorization flow)
For PAT / OAuth credentials, the value is sent as
Authorization: Bearer <value>. Use a personal access token from your Arena account profile (arena_pat_<uuid>_<secret>) to skip OAuth device login. You can also pass a Keycloak access token in the same way if you obtain one elsewhere. Organisation keys (arena_org_…) are for partner servers and must be paired with an external user id.- Parameters:
api_key (str | None) – Bearer token material (profile PAT or OAuth access token). When set, device login is not required.
org_key (str | None) – Organisation API key (
arena_org_…). Requires external_user_id.external_user_id (str | None) – Partner user id sent as
X-External-User-Id. Requires org_key.request_timeout (int) – Default timeout in seconds for API requests.
upload_timeout (int) – Timeout in seconds for file uploads and cluster register.
verbose (bool) – Whether to enable verbose logging.
- Returns:
None
- Return type:
None
- classmethod configure(*, base_url: str | None = None, keycloak_url: str | None = None, realm: str | None = None, client_id: str | None = None) type[ArenaClient]¶
Override default URLs for local development or testing.
Returns the class so calls can be chained with instantiation:
client = ArenaClient.configure( base_url="http://localhost:3001", keycloak_url="http://localhost:8023", )()
- create_dataset(*, name: str, category: str, column_mapping: str | dict[str, Any], description: str | None = None, file: str | PathLike[str] | bytes | None = None, config: str | None = None, hf_dataset_name: str | None = None, hf_config: str | None = None, hf_split: str | None = None) dict[str, Any]¶
Create an LLM dataset on Arena.
Upload a local CSV, a parquet file, a Hugging Face parquet folder, import from HuggingFace, or create metadata only. Validation is performed by the Arena API.
- Parameters:
name (str) – Dataset name.
category (str) – Dataset category (
reasoning,preference,sft,tabular, ornon-tabular).column_mapping (str | dict[str, Any]) – Column mapping as a JSON string or dict.
description (str | None) – Optional description.
file (str | os.PathLike[str] | bytes | None) – Local CSV or parquet path, a directory of parquet shards, or raw CSV bytes (bytes are uploaded as
dataset.csv).config (str | None) – Parquet config name when file is a folder with more than one config (e.g. gsm8k
mainvssocratic).hf_dataset_name (str | None) – HuggingFace dataset id for import.
hf_config (str | None) – HuggingFace dataset config name.
hf_split (str | None) – HuggingFace split (required when importing from HF).
- Returns:
Created dataset metadata from Arena.
- Return type:
- create_project(name: str, description: str | None, llm_based: bool) dict[str, Any]¶
Create a new project in Arena.
- dataset_exists(name: str) dict[str, bool | str]¶
Check whether a dataset name is registered for the active org.
- delete_dataset(name: str, *, confirm: bool = False) dict[str, Any] | None¶
Archive a dataset by name.
- delete_environment(*, name: str, version: str | None = None, confirm: bool = False) dict[str, Any] | None¶
Delete an environment version (or all versions if version is None).
- delete_project(name: str) None¶
Delete a project in Arena.
- Parameters:
name (str) – The name of the project to delete.
- deploy_agent(experiment_name: str, checkpoint: str | None = None, memory_scope: Literal['user', 'organization'] | None = None) dict[str, Any]¶
Create an inference deployment from an experiment checkpoint.
- Parameters:
experiment_name (str) – The name of the experiment to deploy.
checkpoint (str | None) – The checkpoint to deploy. If None, deploy the best checkpoint.
memory_scope (MemoryScope | None) – Who an LLM deployment keeps chat sessions for.
"user"gives every caller their own conversations,"organization"shares them across the organisation. A new deployment defaults to"user". Redeploying withNonekeeps the scope already stored, it does not reset it, and the scope cannot be changed after the deployment exists.
- Returns:
A dictionary containing the deployment result.
- Return type:
- download_experiment_metrics(experiment_name: str, output_path: str | PathLike[str] | None = None, metrics: list[str] | None = None) Path¶
Download experiment metrics to a local file.
- Parameters:
experiment_name (str) – The name of the experiment to download metrics for.
output_path (str | os.PathLike[str] | None) – Destination file path or directory. If a directory, the filename is inferred from the server response. Defaults to
{experiment_name}_metrics.csvin the current directory.metrics (list[str] | None) – The metrics to download. If None, download all metrics.
- Returns:
The path to the written file.
- Return type:
Path
- Raises:
FileExistsError – If the resolved output path already exists.
NotADirectoryError – If the parent path exists but is not a directory.
- duplicate_environment_version(*, name: str, new_version: str, version: str | None = None) dict[str, Any]¶
Duplicate a custom environment version to a new version name.
- environment_exists(name: str, version: str | None = None) bool¶
Check whether an environment name/version is registered.
- get_current_user() dict[str, Any]¶
Get the authenticated user’s profile details.
Includes account fields such as email and name. When the Arena server exposes them, the payload may also contain entitlement flags (e.g. enterprise / BYOC access) relevant to CLI feature gating.
- get_default_project() str | None¶
Return the default project name from
~/.arena/config.json, or None if unset.
- get_default_run_spec(algorithm: str, *, gym_env: str | None = None, gym_env_version: str | None = None, gym_env_entrypoint: str | None = None, dataset_name: str | None = None, field: str | None = None, pretrained_model_name_or_path: str | None = None) dict[str, Any]¶
Fetch a default RunSpec for an algorithm.
fieldreturns one section instead of the full spec.- Parameters:
algorithm (str) – Catalog algorithm name.
gym_env (str | None) – Gym environment display name.
gym_env_version (str | None) – Gym environment version. Required with
gym_env_entrypoint(v1and1are both accepted).gym_env_entrypoint (str | None) – Gym entrypoint.
dataset_name (str | None) – Dataset name.
field (str | None) – RunSpec section to return (
algorithm,environment,mutation,network,replay_buffer,tournament_selection, ortraining).pretrained_model_name_or_path (str | None) – HuggingFace model name in the catalog.
- Returns:
A filled RunSpec, or one section when
fieldis set.- Return type:
- get_model_info(model_name: str) dict[str, Any]¶
Fetch LoRA modules and catalog metadata for a model.
- get_user_credits() None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]¶
Get the authenticated user’s credit information.
- list_checkpoints(experiment_name: str) list[dict[str, Any]]¶
List all checkpoints for an experiment.
- list_datasets(*, search: str | None = None) list[dict[str, Any]]¶
List datasets or search HuggingFace datasets.
- list_environment_entrypoints(name: str, version: str | None = None) list[str]¶
List available entrypoints for an environment version.
- list_environments(name: str | None = None, include_arena: bool = False) dict[str, dict[str, dict[str, bool]]]¶
List environments available to the authenticated user.
- Parameters:
- Returns:
A nested dictionary keyed by environment name, then version:
{ "<name>": { "<version>": { "validated": True, "profiled": True, } } }
- Return type:
- list_experiment_metric_names(experiment_name: str, *, project: str | None = None, details: bool = False) list[dict[str, Any]] | dict[str, Any]¶
List metric catalog rows recorded for an experiment (JSON).
For a CSV preview with
--metric/--preview-rows-style filters, usepreview_experiment_metrics_csv().- Parameters:
- Returns:
Catalog rows
{display_name, category}, or that object whendetailsis True.- Return type:
- list_experiments(project: str | None = None) list[dict[str, Any]]¶
List all experiments in a project.
- list_inference_deployments(*, name: str | None = None, experiment_name: str | None = None, project_name: str | None = None) list[dict[str, Any]]¶
List inference deployments available to the user.
- list_resources() dict[str, Any]¶
List compute resource tiers for Arena training jobs.
Any of the listed resource IDs can be used as the resource_id parameter when submitting a training job through ArenaClient.submit_experiment.
- login(*, timeout: int = 300, force: bool = False) None¶
Start the device-authorization login flow (or reuse a valid stored session).
When force is false (default) and an API key is set, device login is skipped. Organisation-key credentials always skip device login. Pass
force=Trueto run device authorization regardless (useful when the API key is invalid and you want to switch to OAuth).When force is false (default), an unexpired OAuth access token or a successful refresh from
~/.arena/credentials.jsonskips the browser flow. Use force to always run device authorization. On success the tokens are persisted to~/.arena/credentials.json.
- open_inference_agent(deployment_name: str, *, refresh: bool = False, experiment_name: str | None = None, project_name: str | None = None, timeout: int | None = None) Agent¶
Build an
Agentfor a named deployment.Attempts to load the deployment from the cache, and if not found, fetches it from the API.
The agent carries this client’s own credential, so run
login()or setARENA_API_KEYbefore using a deployment that keeps memory per user.- Parameters:
deployment_name (str) – The name of the deployment to open.
refresh (bool) – Whether to refresh the deployment metadata.
experiment_name (str | None) – Experiment name to disambiguate when multiple deployments share the same deployment name.
project_name (str | None) – Project name to disambiguate when multiple deployments share the same deployment name.
A redeploy moves the deployment to a new URL, which leaves the cached one answering 404. Rather than make you pass refresh to find that out, a 404 from the cached URL refetches it once and retries.
- preview_experiment_metrics_csv(experiment_name: str, *, preview_rows: int, metrics: Sequence[str] | None = None, project: str | None = None) tuple[bytes, str | None, str | None]¶
Fetch a capped CSV snippet (Arena CLI
--metric/--preview-rows).Uses
GET /api/cli/v1/experiments/metricswithpreview_rowsset. Omitmetricsto include all columns.- Parameters:
- Returns:
A tuple of the metrics payload, content type, and disposition.
- Return type:
- profile_environment(*, name: str, version: str | None = None) dict[str, Any]¶
Profile a validated environment version.
- resume_experiment(experiment_name: str, max_steps: int) dict[str, Any]¶
Resume an experiment (a training job).
- set_default_project(name: str) None¶
Validate that name exists and persist it as the default project.
- Parameters:
name (str) – The project name to set as default.
- Raises:
ArenaConfigError – If the project does not exist.
- set_stream_handler(handler: Callable[[StatusEvent | CheckEvent | ErrorEvent | LogEvent], None] | None) None¶
Register a callback invoked for each
StreamEventduring streaming.Set to
Noneto clear the handler.
- stop_experiment(experiment_name: str) None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]¶
Stop a running experiment in Arena.
- Parameters:
experiment_name (str) – Experiment name to halt.
- submit_experiment(manifest: str | Path | dict[str, Any], *, resource_id: str | int | None = None, num_nodes: int | None = None, num_gpus: int | None = None, gpu_type: str | None = None, project: str | None = None, experiment_name: str | None = None, reward_file: str | PathLike[str] | bytes | None = None, completion: str | None = None) dict[str, Any]¶
Submit an experiment (a training job).
- Parameters:
manifest (str | Path | dict[str, Any]) – Training manifest as a YAML/JSON file path, raw YAML string, or a pre-parsed dict.
resource_id (str | int | None) – Arena cluster type or resource id for the job.
num_nodes (int | None) – The number of nodes to use for training.
num_gpus (int | None) – Total GPUs for the job. Arena uses the fewest nodes. Cannot be combined with
resource_idornum_nodes.gpu_type (str | None) – Short GPU name such as
h100-80,b200orl4. Cannot be combined withresource_idornum_nodes.project (str | None) – The project to submit the experiment to.
experiment_name (str | None) – The name of the experiment to submit.
reward_file (str | os.PathLike[str] | bytes | None) – Python rubric or reward module scoring a rollout job. When set, the request is sent as
multipart/form-data.completion (str | None) – Optional model completion for reward validation. When omitted, the server uses the reference answer from the first dataset row.
- Raises:
ArenaValidationError – When GPU fields are combined with a node choice, or
num_gpusis below 1.
- validate_environment(*, name: str, version: str | None = None, source: str | PathLike[str] | bytes | None = None, env_config: str | PathLike[str] | None = None, requirements: str | PathLike[str] | None = None, entrypoint: str | None = None, description: str | None = None, multi_agent: bool = False, language_based: bool = False, do_rollouts: bool = False) dict[str, Any]¶
Validate a custom environment on Arena.
When source is provided the environment is uploaded, created, and validated in a single step. When source is None an already-registered environment is validated by name/version.
- Parameters:
name (str) – Environment name.
version (str | None) – Environment version. If creating an environment from scratch, defaults to “v1”, if validating an already-registered environment, defaults to None, which resolves to the latest version.
source (str | os.PathLike[str] | bytes | None) – Environment source — a directory path (compressed automatically), a
.tar.gzfile path, or rawbytes.env_config (str | os.PathLike[str] | None) – Path to the environment configuration file containing the environment parameters. When source is a directory and this is None, a top-level
env_config.yaml,env_config.yml, orenv_config.json(in that order) is picked up automatically. Default is None.requirements (str | os.PathLike[str] | None) – Path to additional dependencies needed for the environment. When source is a directory and this is None, a top-level
requirements.txtis picked up automatically. Default is None.entrypoint (str | None) – Optional entrypoint override. Default is None.
description (str | None) – Optional description of the environment. Default is None.
multi_agent (bool) – Whether the environment is multi-agent. Default is False.
language_based (bool) – Whether the environment follows the GEM API (language-based). Default is False.
do_rollouts (bool) – Whether to perform environment rollouts during validation. Setting this to True will run 100 random episodes and collect additional information such as the average random reward and visualize the rendered environment. Default is False.
- Returns:
A dictionary containing the validation result.
- Return type: