aip_sdk.publish_workspace_metric_config_defaults
aip_sdk.publish_workspace_metric_config_defaults(defaults: Sequence[WorkspaceMetricConfigDefaultSpec], *, workspace_id: str, client: APIClient | None = None) -> list[WorkspaceMetricConfigDefault]
Publish a new default version for each metric in defaults.
workspace_admin only. Each item inserts the next config_version for its metric; the
previous version stays readable and unmodified, and the new one becomes what runs in this
workspace resolve. Versions are server-derived, so this call can never overwrite a stored one.
All-or-nothing on the server: if any item fails validation, none of the batch is written. At
most 500 items per call, and every item's metric.name must be unique
within the batch — a duplicate is rejected rather than silently collapsed, since two versions
published in one call would leave the caller unable to say which became the default.
Not idempotent, and the transport already retries for you. Each call inserts a new version, and the version is server-derived, so there is no key that makes a repeat safe: publishing the same payload twice leaves two versions, and the second is what runs resolve. The underlying client itself retries a request up to twice more on a timeout or network error before this call raises — so by the time you see an exception here, the write may have already landed on one of those attempts.
Set base_version on an item (the config_version last read for it via
list_workspace_metric_config_defaults()) to guard against exactly that: if the lineage
has moved past it — including because this same call already landed once and the transport
is now retrying it — the server rejects the item with
StaleWorkspaceMetricConfigDefaultBaseVersionError instead of
inserting another version. Leaving it unset keeps the old, unguarded behaviour. Either way,
read the current default with list_workspace_metric_config_defaults() before publishing
again after any exception here, rather than assuming nothing was written.
Parameters
defaultsSequence[WorkspaceMetricConfigDefaultSpec]: The defaults to publish, one item per metric. At most 500 items; eachmetric.nameat most once.workspace_idstr: The workspace to configure.clientAPIClient | None: Optional pre-configured API client.
Returns
list[WorkspaceMetricConfigDefault]: list[WorkspaceMetricConfigDefault]: the versions written, in the order given — readlist[WorkspaceMetricConfigDefault]:config_versionto confirm the bump.
Raises
InvalidArgumentError: Ifdefaultsis empty or exceeds the 500-item cap.MetricConfigValidationError: If any item fails server-side validation — including a duplicatemetric.name.NotFoundError: If no workspace has this id.ForbiddenError: If the caller is not aworkspace_adminof this workspace.AuthError: If no credentials are configured.StaleWorkspaceMetricConfigDefaultBaseVersionError: An item'sbase_versionno longer matches its lineage's current version.ServerError: Two publishes landing at the same instant for one metric derive the same next version; the server rejects the loser rather than silently overwriting or re-deriving. Re-read the current default withlist_workspace_metric_config_defaults(), then publish again.APIError: If the write otherwise fails, or the response is malformed.
Example:
published = aip.publish_workspace_metric_config_defaults(
[
aip.WorkspaceMetricConfigDefaultSpec(
metric=aip.MetricRef(name="hallucination", implementation_version="1.0.0"),
config_name="hallucination-strict",
params={"threshold": 0.2},
)
],
workspace_id="ws-abc123",
)
print(published[0].config_version) # the bump over whatever was current