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.
An explicit
base_url/keycloak_urltakes precedence over theARENA_BASE_URL/ARENA_KEYCLOAK_URLenvironment variables.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] | None = None, 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; a local
tracesfile is also checked against the traces spec before upload.- Parameters:
name (str) – Dataset name.
category (str) – Dataset category (
reasoning,preference,sft,traces,tabular, ornon-tabular).column_mapping (str | dict[str, Any] | None) – Column mapping as a JSON string or dict. Required except for
traces, whose column names are the spec.description (str | None) – Optional description.
file (str | os.PathLike[str] | bytes | None) – Local CSV, JSONL 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:
- Raises:
ArenaValidationError – If a
tracesfile breaks the spec.
- 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_inference_deployment(name: str, experiment_name: str | None = None, project_name: str | None = None) dict[str, Any]¶
Archive a deployment.
- 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, num_gpus: int | None = None, gpu_type: str | None = None) dict[str, Any]¶
Create an inference deployment from an experiment checkpoint.
Without
num_gpusorgpu_type, a redeploy keeps the agent’s resources. A new deployment runs on the cluster the agent was trained on if that is your own cluster, else on the cheapest node type that can serve the model. If Arena can’t size the model, it uses its default node type and rejectsnum_gpusandgpu_type.- Parameters:
experiment_name (str) – The name of the experiment to deploy.
checkpoint (str | None) – Steps of the checkpoint to deploy, as listed by
list_checkpoints()(e.g."500"). If None, deploy the checkpoint with the most steps.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.num_gpus (int | None) – GPUs on the agent’s node.
gpu_type (str | None) – Short GPU name such as
h100-80,b200orl4.
- Returns:
A dictionary containing the deployment result.
- Return type:
- Raises:
ArenaValidationError – When
num_gpusis below 1 ormemory_scopeis unknown.
- download_experiment_metrics(experiment_name: str, output_path: str | PathLike[str] | None = None, metrics: list[str] | None = None, project: str | None = None, overwrite: bool = False) 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.
project (str | None) – Project name; defaults to the saved default project.
overwrite (bool) – Replace the file at the resolved output path if it exists.
- Returns:
The path to the written file.
- Return type:
Path
- Raises:
FileExistsError – If the resolved output path is a directory, or is an existing file and
overwriteis False.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_credit_balance() dict[str, Any]¶
Get the active organization’s balance and its accrued, uncharged cost.
- Returns:
balance(spendable credits),accrued_cost(run up by running jobs and deployments but not charged yet),balance_after_accruedandaccrued, one entry per running item withkind,id,experiment_id,name,since,hourly_costandaccrued_cost.- Return type:
- Raises:
ArenaAPIError – With status 404 from an Arena server without accrued cost.
- get_credit_ledger(*, job_id: int | None = None, deployment_id: int | None = None, limit: int | None = None) list[dict[str, Any]]¶
List the active organization’s charges and credits, newest first.
- Parameters:
job_id – Only charges for this job.
deployment_id – Only charges for this deployment.
limit – Most entries to return (the server caps it at 1000).
- Returns:
Entries with
time,kind,job_id,deployment_id,experiment_id,item,description,amount(negative for charges) andbalance(after the entry).- Return type:
- Raises:
ArenaAPIError – With status 404 from an Arena server without the ledger.
- 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, *, env_name: str | None = None, env_version: str | None = None, 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.
env_name (str | None) – Arena environment name.
env_version (str | None) – Environment version. Required with
env_entrypoint(v1and1are both accepted).env_entrypoint (str | None) – Environment 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:
- Raises:
ArenaValidationError – When
algorithmis a classic RL algorithm.
- get_experiment_logs(experiment_name: str, *, tail: int | None = None, after: int | None = None, limit: int | None = None, level: Literal['info', 'warning', 'error'] | None = None, project: str | None = None) dict[str, Any]¶
Return one page of an experiment’s training logs (the web Log view).
- Parameters:
experiment_name (str) – Experiment name (latest match in scope).
tail (int | None) – Return the newest
taillines (1-1000). Not withafter.after (int | None) – Return lines after this line
timestamp(Unix microseconds), oldest first. Pass the previous page’snext_after.limit (int | None) – Lines per page when not tailing (1-1000, server default 500).
level (Literal["info", "warning", "error"] | None) – Lowest severity to return.
project (str | None) – Project, when the experiment name exists in more than one.
- Returns:
The status fields of
get_experiment_status()pluslines(timestamp,severity,message,event_type),next_afterandhas_more.- Return type:
- get_experiment_status(experiment_name: str, project: str | None = None) dict[str, Any]¶
Return an experiment’s status and, when it failed, why.
- 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.
- iter_experiment_logs(experiment_name: str, *, tail: int | None = None, follow: bool = False, level: Literal['info', 'warning', 'error'] | None = None, project: str | None = None, poll_interval: float = 5.0) Iterator[dict[str, Any]]¶
Yield pages of an experiment’s training logs until there are no more.
With
follow, keep polling while the experiment is pending or running, and stop once it has ended and a poll brings no new lines.- Parameters:
experiment_name (str) – Experiment name (latest match in scope).
tail (int | None) – Start with the newest
taillines instead of the first line.follow (bool) – Keep polling for new lines while the experiment runs.
level (Literal["info", "warning", "error"] | None) – Lowest severity to return.
project (str | None) – Project, when the experiment name exists in more than one.
poll_interval (float) – Seconds between polls when following.
- Returns:
Pages as returned by
get_experiment_logs(); the last one carries the finalstatusandfailure_reason.- Return type:
- list_checkpoints(experiment_name: str, project: str | None = None) 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(algorithm: str | None = None) dict[str, Any]¶
List the GPU types and GPU counts a submit accepts.
Each
gpuTypeis a valueArenaClient.submit_experimentaccepts asgpu_type, and each of itsnumGpusa value fornum_gpus. An older platform returns resourcetiersinstead.- Parameters:
algorithm (str | None) – The run’s
algorithm.name. Arena then lists only the GPU counts that algorithm trains on: a GRPO-family run generates on its own GPU, so it needs at least two. Without it the list is for LLM training and includes single GPUs.- Returns:
{"gpuTypes": [{"gpuType": str, "gpusPerNode": list[int], "numGpus": list[int], "devOnly": bool}]}.- Return type:
- login(timeout: int = 300) None¶
Sign in through the browser, then end the previously saved login.
Only one login is kept in
~/.arena/credentials.json, so this is also how to switch user or environment. Organisation-key credentials skip it. An API key stays on this client until the browser sign-in succeeds.- Parameters:
timeout – Maximum seconds to wait for browser authorization.
- 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:
- quote_experiment(manifest: str | Path | dict[str, Any], *, 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]¶
Price an experiment without starting it.
Arena runs the submit checks and picks the class exactly as
submit_experiment()would, then stops before creating anything.Arguments match
submit_experiment().- Returns:
resource_id,resource_name,gpu_type,num_gpus,num_nodes,hourly_cost(credits per hour),max_steps,step_seconds,estimated_hoursandestimated_cost. The last two areNonewhen Arena has no duration estimate.- Return type:
- Raises:
ArenaAPIError – With status 404 from an Arena server that cannot price a run before it starts.
- quote_resume(experiment_name: str, max_steps: int | None = None, checkpoint: str | None = None, new_name: str | None = None, project: str | None = None) dict[str, Any]¶
Price a resume without starting it.
A resume runs on the experiment’s own hardware. Arguments match
resume_experiment().- Returns:
The fields
quote_experiment()returns, for the steps left between the checkpoint andmax_stepson that hardware.- Return type:
- Raises:
ArenaAPIError – With status 404 from an Arena server that cannot price a resume before it starts.
- resume_experiment(experiment_name: str, max_steps: int | None = None, checkpoint: str | None = None, new_name: str | None = None, project: str | None = None) dict[str, Any]¶
Resume an experiment (a training job).
- Parameters:
experiment_name (str) – The name of the experiment to resume.
max_steps (int | None) – Total training steps, counted from the start of the original run; must be greater than the checkpoint’s step. Omit to keep the stored total.
checkpoint (str | None) – Checkpoint to resume from. Omit to use the best checkpoint.
new_name (str | None) – Name for the resumed experiment.
project (str | None) – Project, when the experiment name exists in more than one.
- Returns:
A dictionary containing the resume result.
- Return type:
- 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, project: str | None = None) None | bool | int | float | str | list[JSONValue] | dict[str, JSONValue]¶
Stop a running experiment in Arena.
- submit_experiment(manifest: str | Path | dict[str, Any], *, 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, idempotency_key: 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.
num_gpus (int | None) – Total GPUs for the job. Arena uses the fewest nodes that fit the run’s memory estimate.
gpu_type (str | None) – Short GPU name such as
h100-80,b200orl4.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-dataand a rollout manifest withoutenvironment.rubric_file_pathgets the file’s basename (reward.pyfor bytes).completion (str | None) – Optional model completion for reward validation. When omitted, the server uses the reference answer from the first dataset row.
idempotency_key (str | None) – Reuse this key to replay the same submit instead of starting another job. The key is org-wide.
- Raises:
ArenaValidationError – When
num_gpusis below 1, the manifest turns on HPO, or the manifest’s rubric path names a different file thanreward_file, or a local file whenreward_fileis unset.
- update_inference_deployment(name: str, new_name: str | None = None, description: str | None = None, enabled: bool | None = None, experiment_name: str | None = None, project_name: str | None = None) dict[str, Any]¶
Rename, describe, or enable a deployment.
- Parameters:
name (str) – Current deployment name.
new_name (str | None) – Replacement display name.
description (str | None) – Replacement description.
enabled (bool | None) –
Trueenables the deployment,Falsedisables it.experiment_name (str | None) – Experiment name when several deployments share
name.project_name (str | None) – Project name when several deployments share
name.
- Returns:
The updated deployment.
- Return type:
- 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, do_rollouts: bool = False) dict[str, Any]¶
Validate a custom GEM 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.
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: