Skip to main content

Models Custom Fields

Read and write custom field values on a model.

Methods​

get​

List Model Custom Fields

Every custom field that applies to the model is returned, whether or not a value has been set — an unset field comes back with a null value. Each entry also carries its definition, so you can see a field's type and permitted options without a second call.

fields = client.models("model-123").custom_fields.get()

for field in fields:
print(field.name, field.value)

Returns: A list of CustomFieldValue items


update​

Set Model Custom Field

Sets one custom field value. Identify the field by either custom_field_id or name — exactly one, not both.

from credoai import CustomFieldValueUpdate

# By name
client.models("model-123").custom_fields.update(
CustomFieldValueUpdate(name="Business Unit", value="Finance"),
)

# By ID
client.models("model-123").custom_fields.update(
CustomFieldValueUpdate(custom_field_id="C6K8LCdr8CnrUtNPRTqT28", value="Finance"),
)

# Multi-value fields take a list; null clears a field
client.models("model-123").custom_fields.update(
CustomFieldValueUpdate(name="Reviewers", value=["user-1", "user-2"]),
)
client.models("model-123").custom_fields.update(
CustomFieldValueUpdate(name="Business Unit", value=None),
)

Parameters:

Returns: A list of the updated CustomFieldValue items — always a list, whether you set one field or several.

Setting several fields at once​

Pass values, a map of field name to value, and they are set in one request.

client.models("model-123").custom_fields.update(
CustomFieldValueUpdate(values={
"Business Unit": "Finance",
"Review Tier": 3,
}),
)

Names are resolved before anything is written, so an unknown or ambiguous name fails the whole request with nothing applied.

Setting fields while updating the model​

Custom fields can also be set as part of a model create or update, the same way they can on a use case:

client.models.update(
"model-123",
data=ModelUpdate(
name="Updated name",
custom_fields=[CustomFieldValueUpdate(name="Business Unit", value="Finance")],
),
)

Addressing by name​

Custom field names are not guaranteed unique: a definition that applies to every entity type and one targeted at a specific type can share a name. A name is resolved against the definitions that apply to this use case, and is rejected if it matches none of them or more than one. When a name is ambiguous, the error lists the candidate IDs so you can pass custom_field_id instead.

Error Handling​

StatusMeaning
422Neither or both of custom_field_id and name were given; the name matched no field on this model; the name was ambiguous; or the value did not match the field's type or permitted options.
404No such model.
403The API key's role cannot edit this model.