"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.""" from .basesdk import BaseSDK from jsonpath import JSONPath from openrouter import components, errors, operations, utils from openrouter._hooks import HookContext from openrouter.types import OptionalNullable, UNSET from openrouter.utils import get_security_from_env from openrouter.utils.unmarshal_json_response import unmarshal_json_response from typing import Any, Awaitable, Dict, List, Mapping, Optional, Union class Workspaces(BaseSDK): r"""Workspaces endpoints""" def list( self, *, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, offset: Optional[int] = None, limit: Optional[int] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[operations.ListWorkspacesResponse]: r"""List workspaces List all workspaces for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param offset: Number of records to skip for pagination :param limit: Maximum number of records to return (max 100) :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.ListWorkspacesRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, offset=offset, limit=limit, ) req = self._build_request( method="GET", path="/workspaces", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=False, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.ListWorkspacesGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="listWorkspaces", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "4XX", "500", "5XX"], retry_config=retry_config, ) def next_func() -> Optional[operations.ListWorkspacesResponse]: body = utils.unmarshal_json(http_res.text, Union[Dict[Any, Any], List[Any]]) offset = request.offset if not request.offset is None else 0 if not http_res.text: return None results = JSONPath("$.data").parse(body) if len(results) == 0 or len(results[0]) == 0: return None limit = request.limit if not request.limit is None else 0 if len(results[0]) < limit: return None next_offset = offset + len(results[0]) return self.list( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, offset=next_offset, limit=limit, retries=retries, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return operations.ListWorkspacesResponse( result=unmarshal_json_response( components.ListWorkspacesResponse, http_res ), next=next_func, ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def list_async( self, *, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, offset: Optional[int] = None, limit: Optional[int] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> Optional[operations.ListWorkspacesResponse]: r"""List workspaces List all workspaces for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param offset: Number of records to skip for pagination :param limit: Maximum number of records to return (max 100) :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.ListWorkspacesRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, offset=offset, limit=limit, ) req = self._build_request_async( method="GET", path="/workspaces", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=False, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.ListWorkspacesGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="listWorkspaces", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "4XX", "500", "5XX"], retry_config=retry_config, ) def next_func() -> Awaitable[Optional[operations.ListWorkspacesResponse]]: body = utils.unmarshal_json(http_res.text, Union[Dict[Any, Any], List[Any]]) async def empty_result(): return None offset = request.offset if not request.offset is None else 0 if not http_res.text: return empty_result() results = JSONPath("$.data").parse(body) if len(results) == 0 or len(results[0]) == 0: return empty_result() limit = request.limit if not request.limit is None else 0 if len(results[0]) < limit: return empty_result() next_offset = offset + len(results[0]) return self.list_async( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, offset=next_offset, limit=limit, retries=retries, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return operations.ListWorkspacesResponse( result=unmarshal_json_response( components.ListWorkspacesResponse, http_res ), next=next_func, ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def create( self, *, name: str, slug: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, default_image_model: OptionalNullable[str] = UNSET, default_provider_sort: OptionalNullable[str] = UNSET, default_text_model: OptionalNullable[str] = UNSET, description: OptionalNullable[str] = UNSET, io_logging_api_key_ids: OptionalNullable[List[int]] = UNSET, io_logging_sampling_rate: Optional[float] = None, is_data_discount_logging_enabled: Optional[bool] = None, is_observability_broadcast_enabled: Optional[bool] = None, is_observability_io_logging_enabled: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.CreateWorkspaceResponse: r"""Create a workspace Create a new workspace for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param name: Name for the new workspace :param slug: URL-friendly slug (lowercase alphanumeric segments separated by single hyphens, no leading/trailing hyphens) :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param default_image_model: Default image model for this workspace :param default_provider_sort: Default provider sort preference (price, throughput, latency, exacto) :param default_text_model: Default text model for this workspace :param description: Description of the workspace :param io_logging_api_key_ids: Optional array of API key IDs to filter I/O logging :param io_logging_sampling_rate: Sampling rate for I/O logging (0.0001-1) :param is_data_discount_logging_enabled: Whether data discount logging is enabled :param is_observability_broadcast_enabled: Whether broadcast is enabled :param is_observability_io_logging_enabled: Whether private logging is enabled :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.CreateWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, create_workspace_request=components.CreateWorkspaceRequest( default_image_model=default_image_model, default_provider_sort=default_provider_sort, default_text_model=default_text_model, description=description, io_logging_api_key_ids=io_logging_api_key_ids, io_logging_sampling_rate=io_logging_sampling_rate, is_data_discount_logging_enabled=is_data_discount_logging_enabled, is_observability_broadcast_enabled=is_observability_broadcast_enabled, is_observability_io_logging_enabled=is_observability_io_logging_enabled, name=name, slug=slug, ), ) req = self._build_request( method="POST", path="/workspaces", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=False, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.CreateWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.create_workspace_request, False, False, "json", components.CreateWorkspaceRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="createWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "201", "application/json"): return unmarshal_json_response(components.CreateWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def create_async( self, *, name: str, slug: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, default_image_model: OptionalNullable[str] = UNSET, default_provider_sort: OptionalNullable[str] = UNSET, default_text_model: OptionalNullable[str] = UNSET, description: OptionalNullable[str] = UNSET, io_logging_api_key_ids: OptionalNullable[List[int]] = UNSET, io_logging_sampling_rate: Optional[float] = None, is_data_discount_logging_enabled: Optional[bool] = None, is_observability_broadcast_enabled: Optional[bool] = None, is_observability_io_logging_enabled: Optional[bool] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.CreateWorkspaceResponse: r"""Create a workspace Create a new workspace for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param name: Name for the new workspace :param slug: URL-friendly slug (lowercase alphanumeric segments separated by single hyphens, no leading/trailing hyphens) :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param default_image_model: Default image model for this workspace :param default_provider_sort: Default provider sort preference (price, throughput, latency, exacto) :param default_text_model: Default text model for this workspace :param description: Description of the workspace :param io_logging_api_key_ids: Optional array of API key IDs to filter I/O logging :param io_logging_sampling_rate: Sampling rate for I/O logging (0.0001-1) :param is_data_discount_logging_enabled: Whether data discount logging is enabled :param is_observability_broadcast_enabled: Whether broadcast is enabled :param is_observability_io_logging_enabled: Whether private logging is enabled :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.CreateWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, create_workspace_request=components.CreateWorkspaceRequest( default_image_model=default_image_model, default_provider_sort=default_provider_sort, default_text_model=default_text_model, description=description, io_logging_api_key_ids=io_logging_api_key_ids, io_logging_sampling_rate=io_logging_sampling_rate, is_data_discount_logging_enabled=is_data_discount_logging_enabled, is_observability_broadcast_enabled=is_observability_broadcast_enabled, is_observability_io_logging_enabled=is_observability_io_logging_enabled, name=name, slug=slug, ), ) req = self._build_request_async( method="POST", path="/workspaces", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=False, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.CreateWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.create_workspace_request, False, False, "json", components.CreateWorkspaceRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="createWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "201", "application/json"): return unmarshal_json_response(components.CreateWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def delete( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.DeleteWorkspaceResponse: r"""Delete a workspace Delete an existing workspace. The default workspace cannot be deleted. Workspaces with active API keys cannot be deleted. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.DeleteWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request( method="DELETE", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.DeleteWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="deleteWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.DeleteWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def delete_async( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.DeleteWorkspaceResponse: r"""Delete a workspace Delete an existing workspace. The default workspace cannot be deleted. Workspaces with active API keys cannot be deleted. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.DeleteWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request_async( method="DELETE", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.DeleteWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="deleteWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.DeleteWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def get( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.GetWorkspaceResponse: r"""Get a workspace Get a single workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.GetWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request( method="GET", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.GetWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="getWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.GetWorkspaceResponse, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def get_async( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.GetWorkspaceResponse: r"""Get a workspace Get a single workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.GetWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request_async( method="GET", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.GetWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="getWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.GetWorkspaceResponse, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def update( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, default_image_model: OptionalNullable[str] = UNSET, default_provider_sort: OptionalNullable[str] = UNSET, default_text_model: OptionalNullable[str] = UNSET, description: OptionalNullable[str] = UNSET, io_logging_api_key_ids: OptionalNullable[List[int]] = UNSET, io_logging_sampling_rate: Optional[float] = None, is_data_discount_logging_enabled: Optional[bool] = None, is_observability_broadcast_enabled: Optional[bool] = None, is_observability_io_logging_enabled: Optional[bool] = None, name: Optional[str] = None, slug: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.UpdateWorkspaceResponse: r"""Update a workspace Update an existing workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param default_image_model: Default image model for this workspace :param default_provider_sort: Default provider sort preference (price, throughput, latency, exacto) :param default_text_model: Default text model for this workspace :param description: New description for the workspace :param io_logging_api_key_ids: Optional array of API key IDs to filter I/O logging :param io_logging_sampling_rate: Sampling rate for I/O logging (0.0001-1) :param is_data_discount_logging_enabled: Whether data discount logging is enabled :param is_observability_broadcast_enabled: Whether broadcast is enabled :param is_observability_io_logging_enabled: Whether private logging is enabled :param name: New name for the workspace :param slug: New URL-friendly slug (lowercase alphanumeric segments separated by single hyphens, no leading/trailing hyphens) :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.UpdateWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, update_workspace_request=components.UpdateWorkspaceRequest( default_image_model=default_image_model, default_provider_sort=default_provider_sort, default_text_model=default_text_model, description=description, io_logging_api_key_ids=io_logging_api_key_ids, io_logging_sampling_rate=io_logging_sampling_rate, is_data_discount_logging_enabled=is_data_discount_logging_enabled, is_observability_broadcast_enabled=is_observability_broadcast_enabled, is_observability_io_logging_enabled=is_observability_io_logging_enabled, name=name, slug=slug, ), ) req = self._build_request( method="PATCH", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.UpdateWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.update_workspace_request, False, False, "json", components.UpdateWorkspaceRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="updateWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.UpdateWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def update_async( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, default_image_model: OptionalNullable[str] = UNSET, default_provider_sort: OptionalNullable[str] = UNSET, default_text_model: OptionalNullable[str] = UNSET, description: OptionalNullable[str] = UNSET, io_logging_api_key_ids: OptionalNullable[List[int]] = UNSET, io_logging_sampling_rate: Optional[float] = None, is_data_discount_logging_enabled: Optional[bool] = None, is_observability_broadcast_enabled: Optional[bool] = None, is_observability_io_logging_enabled: Optional[bool] = None, name: Optional[str] = None, slug: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.UpdateWorkspaceResponse: r"""Update a workspace Update an existing workspace by ID or slug. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param default_image_model: Default image model for this workspace :param default_provider_sort: Default provider sort preference (price, throughput, latency, exacto) :param default_text_model: Default text model for this workspace :param description: New description for the workspace :param io_logging_api_key_ids: Optional array of API key IDs to filter I/O logging :param io_logging_sampling_rate: Sampling rate for I/O logging (0.0001-1) :param is_data_discount_logging_enabled: Whether data discount logging is enabled :param is_observability_broadcast_enabled: Whether broadcast is enabled :param is_observability_io_logging_enabled: Whether private logging is enabled :param name: New name for the workspace :param slug: New URL-friendly slug (lowercase alphanumeric segments separated by single hyphens, no leading/trailing hyphens) :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.UpdateWorkspaceRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, update_workspace_request=components.UpdateWorkspaceRequest( default_image_model=default_image_model, default_provider_sort=default_provider_sort, default_text_model=default_text_model, description=description, io_logging_api_key_ids=io_logging_api_key_ids, io_logging_sampling_rate=io_logging_sampling_rate, is_data_discount_logging_enabled=is_data_discount_logging_enabled, is_observability_broadcast_enabled=is_observability_broadcast_enabled, is_observability_io_logging_enabled=is_observability_io_logging_enabled, name=name, slug=slug, ), ) req = self._build_request_async( method="PATCH", path="/workspaces/{id}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.UpdateWorkspaceGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.update_workspace_request, False, False, "json", components.UpdateWorkspaceRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="updateWorkspace", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response(components.UpdateWorkspaceResponse, http_res) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def list_budgets( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.ListWorkspaceBudgetsResponse: r"""List workspace budgets List all budgets configured for a workspace. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.ListWorkspaceBudgetsRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request( method="GET", path="/workspaces/{id}/budgets", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.ListWorkspaceBudgetsGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="listWorkspaceBudgets", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.ListWorkspaceBudgetsResponse, http_res ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def list_budgets_async( self, *, id: str, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.ListWorkspaceBudgetsResponse: r"""List workspace budgets List all budgets configured for a workspace. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.ListWorkspaceBudgetsRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, ) req = self._build_request_async( method="GET", path="/workspaces/{id}/budgets", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.ListWorkspaceBudgetsGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="listWorkspaceBudgets", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.ListWorkspaceBudgetsResponse, http_res ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def delete_budget( self, *, id: str, interval: components.WorkspaceBudgetInterval, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.DeleteWorkspaceBudgetResponse: r"""Delete a workspace budget Remove the budget for a given interval. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param interval: Budget reset interval. Use \"lifetime\" for a one-time budget that never resets. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.DeleteWorkspaceBudgetRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, interval=interval, ) req = self._build_request( method="DELETE", path="/workspaces/{id}/budgets/{interval}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.DeleteWorkspaceBudgetGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="deleteWorkspaceBudget", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.DeleteWorkspaceBudgetResponse, http_res ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def delete_budget_async( self, *, id: str, interval: components.WorkspaceBudgetInterval, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.DeleteWorkspaceBudgetResponse: r"""Delete a workspace budget Remove the budget for a given interval. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param interval: Budget reset interval. Use \"lifetime\" for a one-time budget that never resets. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.DeleteWorkspaceBudgetRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, interval=interval, ) req = self._build_request_async( method="DELETE", path="/workspaces/{id}/budgets/{interval}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=False, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.DeleteWorkspaceBudgetGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="deleteWorkspaceBudget", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.DeleteWorkspaceBudgetResponse, http_res ) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def set_budget( self, *, id: str, interval: components.WorkspaceBudgetInterval, limit_usd: float, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.UpsertWorkspaceBudgetResponse: r"""Create or update a workspace budget Create or update the budget for a given interval. Budget limits must strictly decrease as the interval narrows (lifetime > monthly > weekly > daily). [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param interval: Budget reset interval. Use \"lifetime\" for a one-time budget that never resets. :param limit_usd: Spending limit in USD. Must be greater than 0. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.UpsertWorkspaceBudgetRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, interval=interval, upsert_workspace_budget_request=components.UpsertWorkspaceBudgetRequest( limit_usd=limit_usd, ), ) req = self._build_request( method="PUT", path="/workspaces/{id}/budgets/{interval}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.UpsertWorkspaceBudgetGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.upsert_workspace_budget_request, False, False, "json", components.UpsertWorkspaceBudgetRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="upsertWorkspaceBudget", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.UpsertWorkspaceBudgetResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def set_budget_async( self, *, id: str, interval: components.WorkspaceBudgetInterval, limit_usd: float, http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.UpsertWorkspaceBudgetResponse: r"""Create or update a workspace budget Create or update the budget for a given interval. Budget limits must strictly decrease as the interval narrows (lifetime > monthly > weekly > daily). [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param interval: Budget reset interval. Use \"lifetime\" for a one-time budget that never resets. :param limit_usd: Spending limit in USD. Must be greater than 0. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.UpsertWorkspaceBudgetRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, interval=interval, upsert_workspace_budget_request=components.UpsertWorkspaceBudgetRequest( limit_usd=limit_usd, ), ) req = self._build_request_async( method="PUT", path="/workspaces/{id}/budgets/{interval}", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.UpsertWorkspaceBudgetGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.upsert_workspace_budget_request, False, False, "json", components.UpsertWorkspaceBudgetRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="upsertWorkspaceBudget", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.UpsertWorkspaceBudgetResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def bulk_add_members( self, *, id: str, user_ids: List[str], http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.BulkAddWorkspaceMembersResponse: r"""Bulk add members to a workspace Add multiple organization members to a workspace. Members are assigned the same role they hold in the organization. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param user_ids: List of user IDs to add to the workspace. Members are assigned the same role they hold in the organization. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.BulkAddWorkspaceMembersRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, bulk_add_workspace_members_request=components.BulkAddWorkspaceMembersRequest( user_ids=user_ids, ), ) req = self._build_request( method="POST", path="/workspaces/{id}/members/add", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.BulkAddWorkspaceMembersGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.bulk_add_workspace_members_request, False, False, "json", components.BulkAddWorkspaceMembersRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="bulkAddWorkspaceMembers", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.BulkAddWorkspaceMembersResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def bulk_add_members_async( self, *, id: str, user_ids: List[str], http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.BulkAddWorkspaceMembersResponse: r"""Bulk add members to a workspace Add multiple organization members to a workspace. Members are assigned the same role they hold in the organization. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param user_ids: List of user IDs to add to the workspace. Members are assigned the same role they hold in the organization. :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.BulkAddWorkspaceMembersRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, bulk_add_workspace_members_request=components.BulkAddWorkspaceMembersRequest( user_ids=user_ids, ), ) req = self._build_request_async( method="POST", path="/workspaces/{id}/members/add", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.BulkAddWorkspaceMembersGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.bulk_add_workspace_members_request, False, False, "json", components.BulkAddWorkspaceMembersRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="bulkAddWorkspaceMembers", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.BulkAddWorkspaceMembersResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) def bulk_remove_members( self, *, id: str, user_ids: List[str], http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.BulkRemoveWorkspaceMembersResponse: r"""Bulk remove members from a workspace Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param user_ids: List of user IDs to remove from the workspace :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.BulkRemoveWorkspaceMembersRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, bulk_remove_workspace_members_request=components.BulkRemoveWorkspaceMembersRequest( user_ids=user_ids, ), ) req = self._build_request( method="POST", path="/workspaces/{id}/members/remove", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.BulkRemoveWorkspaceMembersGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.bulk_remove_workspace_members_request, False, False, "json", components.BulkRemoveWorkspaceMembersRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = self.do_request( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="bulkRemoveWorkspaceMembers", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.BulkRemoveWorkspaceMembersResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = utils.stream_to_text(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res) async def bulk_remove_members_async( self, *, id: str, user_ids: List[str], http_referer: Optional[str] = None, x_open_router_title: Optional[str] = None, x_open_router_categories: Optional[str] = None, retries: OptionalNullable[utils.RetryConfig] = UNSET, server_url: Optional[str] = None, timeout_ms: Optional[int] = None, http_headers: Optional[Mapping[str, str]] = None, ) -> components.BulkRemoveWorkspaceMembersResponse: r"""Bulk remove members from a workspace Remove multiple members from a workspace. Members with active API keys in the workspace cannot be removed. [Management key](/docs/guides/overview/auth/management-api-keys) required. :param id: The workspace ID (UUID) or slug :param user_ids: List of user IDs to remove from the workspace :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings. This is used to track API usage per application. :param x_open_router_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard. :param x_open_router_categories: Comma-separated list of app categories (e.g. \"cli-agent,cloud-agent\"). Used for marketplace rankings. :param retries: Override the default retry configuration for this method :param server_url: Override the default server URL for this method :param timeout_ms: Override the default request timeout configuration for this method in milliseconds :param http_headers: Additional headers to set or replace on requests. """ base_url = None url_variables = None if timeout_ms is None: timeout_ms = self.sdk_configuration.timeout_ms if server_url is not None: base_url = server_url else: base_url = self._get_url(base_url, url_variables) request = operations.BulkRemoveWorkspaceMembersRequest( http_referer=http_referer, x_open_router_title=x_open_router_title, x_open_router_categories=x_open_router_categories, id=id, bulk_remove_workspace_members_request=components.BulkRemoveWorkspaceMembersRequest( user_ids=user_ids, ), ) req = self._build_request_async( method="POST", path="/workspaces/{id}/members/remove", base_url=base_url, url_variables=url_variables, request=request, request_body_required=True, request_has_path_params=True, request_has_query_params=True, user_agent_header="user-agent", accept_header_value="application/json", http_headers=http_headers, _globals=operations.BulkRemoveWorkspaceMembersGlobals( http_referer=self.sdk_configuration.globals.http_referer, x_open_router_title=self.sdk_configuration.globals.x_open_router_title, x_open_router_categories=self.sdk_configuration.globals.x_open_router_categories, ), security=self.sdk_configuration.security, get_serialized_body=lambda: utils.serialize_request_body( request.bulk_remove_workspace_members_request, False, False, "json", components.BulkRemoveWorkspaceMembersRequest, ), allow_empty_value=None, timeout_ms=timeout_ms, ) if retries == UNSET: if self.sdk_configuration.retry_config is not UNSET: retries = self.sdk_configuration.retry_config else: retries = utils.RetryConfig( "backoff", utils.BackoffStrategy(500, 60000, 1.5, 3600000), True ) retry_config = None if isinstance(retries, utils.RetryConfig): retry_config = (retries, ["5XX"]) http_res = await self.do_request_async( hook_ctx=HookContext( config=self.sdk_configuration, base_url=base_url or "", operation_id="bulkRemoveWorkspaceMembers", oauth2_scopes=None, security_source=get_security_from_env( self.sdk_configuration.security, components.Security ), ), request=req, error_status_codes=["400", "401", "403", "404", "4XX", "500", "5XX"], retry_config=retry_config, ) response_data: Any = None if utils.match_response(http_res, "200", "application/json"): return unmarshal_json_response( components.BulkRemoveWorkspaceMembersResponse, http_res ) if utils.match_response(http_res, "400", "application/json"): response_data = unmarshal_json_response( errors.BadRequestResponseErrorData, http_res ) raise errors.BadRequestResponseError(response_data, http_res) if utils.match_response(http_res, "401", "application/json"): response_data = unmarshal_json_response( errors.UnauthorizedResponseErrorData, http_res ) raise errors.UnauthorizedResponseError(response_data, http_res) if utils.match_response(http_res, "403", "application/json"): response_data = unmarshal_json_response( errors.ForbiddenResponseErrorData, http_res ) raise errors.ForbiddenResponseError(response_data, http_res) if utils.match_response(http_res, "404", "application/json"): response_data = unmarshal_json_response( errors.NotFoundResponseErrorData, http_res ) raise errors.NotFoundResponseError(response_data, http_res) if utils.match_response(http_res, "500", "application/json"): response_data = unmarshal_json_response( errors.InternalServerResponseErrorData, http_res ) raise errors.InternalServerResponseError(response_data, http_res) if utils.match_response(http_res, "4XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) if utils.match_response(http_res, "5XX", "*"): http_res_text = await utils.stream_to_text_async(http_res) raise errors.OpenRouterDefaultError( "API error occurred", http_res, http_res_text ) raise errors.OpenRouterDefaultError("Unexpected response received", http_res)