Workspaces Client¶
The Workspaces client provides methods for managing workspaces in the Opik platform.
- class opik.rest_api.workspaces.client.WorkspacesClient(*, client_wrapper: SyncClientWrapper)¶
Bases:
object- costs_summary(*, interval_start: datetime, interval_end: datetime, project_ids: Sequence[str] | None = OMIT, start_before_end: bool | None = OMIT, request_options: RequestOptions | None = None) Result¶
Get costs summary
- Parameters:
interval_start (dt.datetime)
interval_end (dt.datetime)
project_ids (Optional[Sequence[str]])
start_before_end (Optional[bool])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace Metrics
- Return type:
- get_workspace_configuration(*, request_options: RequestOptions | None = None) WorkspaceConfiguration¶
Get workspace configuration
- Parameters:
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace Configuration
- Return type:
- upsert_workspace_configuration(*, timeout_to_mark_thread_as_inactive: str | None = OMIT, truncation_on_tables: bool | None = OMIT, color_map: Dict[str, str] | None = OMIT, request_options: RequestOptions | None = None) WorkspaceConfiguration¶
Upsert workspace configuration
- Parameters:
timeout_to_mark_thread_as_inactive (Optional[str]) – Duration in ISO-8601 format (e.g., PT30M for 30 minutes, PT2H for 2 hours, P1D for 1 day). Minimum precision supported is seconds, please use a duration with seconds precision or higher. Also, the max duration allowed is 7 days.
truncation_on_tables (Optional[bool]) – Enable or disable data truncation in table views. When disabled, the frontend will limit pagination to prevent performance issues. Default: true (truncation enabled).
color_map (Optional[Dict[str, str]]) – Workspace-level color map. Maps label names to hex color values (e.g. #FF0000). Max 10000 entries.
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Configuration Updated
- Return type:
- delete_workspace_configuration(*, request_options: RequestOptions | None = None) None¶
Delete workspace configuration
- Parameters:
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Return type:
None
- get_cost(*, interval_start: datetime, interval_end: datetime, project_ids: Sequence[str] | None = OMIT, start_before_end: bool | None = OMIT, request_options: RequestOptions | None = None) WorkspaceMetricResponse¶
Get cost daily data
- Parameters:
interval_start (dt.datetime)
interval_end (dt.datetime)
project_ids (Optional[Sequence[str]])
start_before_end (Optional[bool])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace cost data by days
- Return type:
- get_metric(*, interval_start: datetime, interval_end: datetime, project_ids: Sequence[str] | None = OMIT, start_before_end: bool | None = OMIT, request_options: RequestOptions | None = None) WorkspaceMetricResponse¶
Get metric daily data
- Parameters:
interval_start (dt.datetime)
interval_end (dt.datetime)
project_ids (Optional[Sequence[str]])
start_before_end (Optional[bool])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace metric data by days
- Return type:
- get_workspace_span_metric(*, interval_start: datetime, project_ids: Sequence[str] | None = OMIT, metric_type: Literal['FEEDBACK_SCORES', 'TRACE_COUNT', 'TOKEN_USAGE', 'DURATION', 'COST', 'GUARDRAILS_FAILED_COUNT', 'THREAD_COUNT', 'THREAD_DURATION', 'THREAD_FEEDBACK_SCORES', 'SPAN_FEEDBACK_SCORES', 'SPAN_COUNT', 'SPAN_DURATION', 'SPAN_TOKEN_USAGE', 'TRACE_AVERAGE_DURATION', 'TRACE_ERROR_RATE', 'SPAN_AVERAGE_DURATION', 'SPAN_COST', 'SPAN_ERROR_RATE', 'THREAD_AVERAGE_DURATION', 'THREAD_COST'] | Any | None = OMIT, interval: Literal['HOURLY', 'DAILY', 'WEEKLY', 'TOTAL'] | Any | None = OMIT, breakdown: BreakdownConfig | None = OMIT, filters: Sequence[SpanFilter] | None = OMIT, interval_end: datetime | None = OMIT, start_before_end: bool | None = OMIT, request_options: RequestOptions | None = None) WorkspaceMetricResponse¶
Gets a span metric time series aggregated across the workspace. When project_ids is empty, all projects in the workspace are included; otherwise only the given projects.
- Parameters:
interval_start (dt.datetime)
project_ids (Optional[Sequence[str]])
metric_type (Optional[WorkspaceSpanMetricRequestMetricType])
interval (Optional[WorkspaceSpanMetricRequestInterval])
breakdown (Optional[BreakdownConfig])
filters (Optional[Sequence[SpanFilter]])
interval_end (Optional[dt.datetime])
start_before_end (Optional[bool])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace span metric
- Return type:
- get_workspace_version(*, request_options: RequestOptions | None = None) WorkspaceVersion¶
Determines whether the workspace should use Opik V1 (legacy workspace-scoped) or Opik V2 (project-first) navigation. The backend is the single authority for this determination, clients must never derive the version themselves.
Determination logic (priority order): 1) V2 workspace allowlist (TOGGLE_V2_WORKSPACE_ALLOWLIST) 2) Feature flag override (TOGGLE_FORCE_WORKSPACE_VERSION) 3) Auth one-way V2 gate (authenticated mode only) 4) Version 1 entity check (entities without project_id) 5) Fallback on failure
In unauthenticated mode (authentication.enabled=false), auth steps are skipped. Called by the frontend on workspace load.
- Parameters:
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace version
- Return type:
- metrics_summary(*, interval_start: datetime, interval_end: datetime, project_ids: Sequence[str] | None = OMIT, start_before_end: bool | None = OMIT, request_options: RequestOptions | None = None) WorkspaceMetricsSummaryResponse¶
Get metrics summary
- Parameters:
interval_start (dt.datetime)
interval_end (dt.datetime)
project_ids (Optional[Sequence[str]])
start_before_end (Optional[bool])
request_options (Optional[RequestOptions]) – Request-specific configuration.
- Returns:
Workspace Metrics
- Return type:
Usage Example¶
import opik
client = opik.Opik()
# Get workspace information
workspace = client.rest_client.workspaces.get_workspace()
# Get workspace statistics
stats = client.rest_client.workspaces.get_workspace_stats()