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:

  1. org_key plus external_user_id (constructor or ARENA_ORG_KEY / ARENA_EXTERNAL_USER_ID). Sends Authorization: Bearer <org key> and X-External-User-Id.

  2. api_key constructor argument

  3. ARENA_API_KEY environment variable

  4. Stored OAuth credentials from ~/.arena/credentials.json

  5. Interactive 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

BASE_URL: ClassVar[str] = 'https://arena.agilerl.com'
CONFIG_DIR: ClassVar[Path] = PosixPath('/home/docs/.arena')
CONFIG_FILE: ClassVar[Path] = PosixPath('/home/docs/.arena/config.json')
close() → None

Close the underlying HTTP connection pool.

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, or non-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 main vs socratic).

  • 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:

dict[str, Any]

create_project(name: str, description: str | None, llm_based: bool) → dict[str, Any]

Create a new project in Arena.

Parameters:
  • name (str) – The name of the project to create.

  • description (str | None) – The description of the project to create.

  • llm_based (bool) – Whether the project is based on an LLM.

Returns:

A dictionary containing the project creation result.

Return type:

dict[str, Any]

dataset_exists(name: str) → dict[str, bool | str]

Check whether a dataset name is registered for the active org.

Parameters:

name (str) – Dataset name.

Returns:

exists, and datasetType when the name is registered.

Return type:

dict[str, bool | str]

delete_dataset(name: str, *, confirm: bool = False) → dict[str, Any] | None

Archive a dataset by name.

Parameters:
  • name (str) – Dataset name.

  • confirm (bool) – When True, skip the interactive confirmation prompt.

Returns:

Archive result, or None if the user declined confirmation.

Return type:

dict[str, Any] | None

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).

Parameters:
  • name (str) – Environment name, as specified in Arena.

  • version (str | None) – Environment version. If None, delete all environment versions.

  • confirm (bool) – Whether to confirm the deletion.

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 with None keeps 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:

dict[str, Any]

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.csv in 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:
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.

Parameters:
  • name (str) – Environment name.

  • new_version (str) – New version for the duplicate (e.g. v2).

  • version (str | None) – Source version; when omitted, the latest version is used.

environment_exists(name: str, version: str | None = None) → bool

Check whether an environment name/version is registered.

Parameters:
  • name (str) – Environment name.

  • version (str | None) – Environment version. Defaults to None, which resolves to the latest version.

Returns:

True if the environment exists, False otherwise.

Return type:

bool

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.

field returns 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 (v1 and 1 are 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, or training).

  • pretrained_model_name_or_path (str | None) – HuggingFace model name in the catalog.

Returns:

A filled RunSpec, or one section when field is set.

Return type:

dict[str, Any]

get_model_info(model_name: str) → dict[str, Any]

Fetch LoRA modules and catalog metadata for a model.

Parameters:

model_name (str) – HuggingFace model id as stored in the catalog.

Returns:

modules, parameters, lora_info, num_params, max_context_length, and lora_ranks.

Return type:

dict[str, Any]

get_user_credits() → None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]

Get the authenticated user’s credit information.

property is_authenticated: bool

True when the client holds an org key, API key, or access token.

list_checkpoints(experiment_name: str) → list[dict[str, Any]]

List all checkpoints for an experiment.

Parameters:

experiment_name (str) – The name of the experiment to list checkpoints for.

Returns:

A list of checkpoints.

Return type:

list[dict[str, Any]]

list_datasets(*, search: str | None = None) → list[dict[str, Any]]

List datasets or search HuggingFace datasets.

Parameters:

search (str | None) – HuggingFace dataset search query.

Returns:

List of datasets or search results from Arena.

Return type:

list[dict[str, Any]]

list_environment_entrypoints(name: str, version: str | None = None) → list[str]

List available entrypoints for an environment version.

Parameters:
  • name (str) – Environment name, as specified in Arena.

  • version (str | None) – Environment version. Defaults to None, which resolves to the latest version.

Returns:

A list of entrypoints.

Return type:

list[str]

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:
  • name (str | None) – Environment name. If None, list all environments.

  • include_arena (bool) – Whether to include off-the-shelf Gymnasium/PettingZoo environments available in Arena.

Returns:

A nested dictionary keyed by environment name, then version:

{
    "<name>": {
        "<version>": {
            "validated": True,
            "profiled": True,
        }
    }
}

Return type:

dict[str, dict[str, dict[str, bool]]]

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, use preview_experiment_metrics_csv().

Parameters:
  • experiment_name (str) – Experiment name (latest updated match in scope).

  • project (str | None) – Optional exact project name in the current org.

  • details (bool) – When True, the API returns {\"metrics\": […catalog…]}.

Returns:

Catalog rows {display_name, category}, or that object when details is True.

Return type:

list[dict[str, Any]] | dict[str, Any]

list_experiments(project: str | None = None) → list[dict[str, Any]]

List all experiments in a project.

Parameters:

project (str | None) – The name of the project. Falls back to the default project from ~/.arena/config.json if not provided.

Returns:

A list of experiments.

Return type:

list[dict[str, Any]]

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.

Parameters:
  • name (str | None) – The name of the deployment to list.

  • experiment_name (str | None) – The name of the experiment to list deployments for.

  • project_name (str | None) – The name of the project to list deployments for.

Returns:

A list of deployments.

Return type:

list[dict[str, Any]]

list_models() → list[dict[str, Any]]

List HuggingFace models in the Arena catalog.

Returns:

Catalog rows including model_name, num_params, lora_info, max_context_length, lora_ranks, and enabled.

Return type:

list[dict[str, Any]]

list_projects() → list[dict[str, Any]]

List all projects in Arena for the authenticated user.

Returns:

A list of projects.

Return type:

list[dict[str, Any]]

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.

Returns:

A dictionary of resource tiers.

Return type:

dict[str, Any]

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=True to 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.json skips the browser flow. Use force to always run device authorization. On success the tokens are persisted to ~/.arena/credentials.json.

logout() → None

Clear the current session and remove stored credentials.

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 Agent for 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 set ARENA_API_KEY before 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.

Parameters:

timeout (int | None) – HTTP timeout in seconds for the returned agent’s inference requests.

Returns:

An Agent instance.

Return type:

Agent

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/metrics with preview_rows set. Omit metrics to include all columns.

Parameters:
  • experiment_name (str) – Experiment name (latest match in scope).

  • preview_rows (int) – Maximum number of data rows in the CSV (server-capped).

  • metrics (Sequence[str] | None) – Metric column names to include (repeat query param metric).

  • project (str | None) – Optional exact project name.

Returns:

A tuple of the metrics payload, content type, and disposition.

Return type:

tuple[bytes, str | None, str | None]

profile_environment(*, name: str, version: str | None = None) → dict[str, Any]

Profile a validated environment version.

Parameters:
  • name (str) – Environment name, as specified in Arena.

  • version (str | None) – Environment version. Defaults to None, which resolves to the latest version.

resume_experiment(experiment_name: str, max_steps: int) → dict[str, Any]

Resume an experiment (a training job).

Parameters:
  • experiment_name (str) – The name of the experiment to resume.

  • max_steps (int) – The maximum number of steps to train for.

Returns:

A dictionary containing the resume result.

Return type:

dict[str, Any]

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 StreamEvent during streaming.

Set to None to 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_id or num_nodes.

  • gpu_type (str | None) – Short GPU name such as h100-80, b200 or l4. Cannot be combined with resource_id or num_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_gpus is 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.gz file path, or raw bytes.

  • 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, or env_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.txt is 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:

dict[str, Any]