Base

APIClient

class client.APIClient(credentials=None, project_id=None, space_id=None, verify=None, **kwargs)[source]

Main class of ibm_watsonx_ai. The very heart of the module. APIClient contains objects managing service reasources.

To explore usage of APIClient refer to:
  • Setup section - to check correct initialisation of APIClient for specific environment

  • Core section - to explore core properties of APIClient object

Parameters:
  • url (str) – service url

  • credentials (Credentials) – credentials used to connect with the service

  • project_id (str, optional) – ID of used project

  • space_id (str, optional) – ID of used deployment space

  • verify (bool, optional) – certificate verification flag, deprecated, use Credentials(verify=…) to set verify

Example

from ibm_watsonx_ai import APIClient, Credentials

credentials = Credentials(
    url = "<url>",
    api_key = "<api_key>"
)

client = APIClient(credentials, space_id="<space_id>")

client.models.list()
client.deployments.get_details()

client.set.default_project("<project_id>")

...

Credentials

class credentials.Credentials(*, url=None, api_key=None, name=None, iam_serviceid_crn=None, token=None, projects_token=None, username=None, password=None, instance_id=None, version=None, bedrock_url=None, proxies=None, verify=None)[source]

This class encapsulate passed credentials and additional params.

Parameters:
  • url (str) – service url

  • api_key (str, optional) – service API key, used in API key authentication

  • name (str, optional) – service name, used during space creation for Cloud environment

  • iam_serviceid_crn (str, optional) – service CRN, used during space creation for Cloud environment

  • token (str, optional) – service token, used in token authentication

  • projects_token (str, optional) – service projects token, used in token authentication

  • username (str, optional) – username, used in username/password or username/api_key authentication, applicable for ICP only

  • password (str, optional) – password, used in username/password authentication, applicable for ICP only

  • instance_id (str, optional) – instance ID, mandatory for ICP

  • version (str, optional) – ICP version, mandatory for ICP

  • bedrock_url (str, optional) – Bedrock url, applicable for ICP only

  • proxies (dict, optional) – dictionary of proxies, containing protocol and url mapping (example: { “https”: “https://example.url.com” })

  • verify (bool, optional) – certificate verification flag

static from_dict(credentials, _verify=None)[source]

Create a Credentials object from dictionary.

Parameters:

credentials (dict) – credentials in the dictionary

Returns:

initialised Credentials object

Return type:

Credentials

Example

from ibm_watsonx_ai import Credentials

credentials = Credentials.from_dict({
    'url': "<url>",
    'apikey': "<api_key>"
})
to_dict()[source]

Get dictionary from the Credentials object.

Returns:

dictionary with credentials

Return type:

dict

Example

from ibm_watsonx_ai import Credentials

credentials = Credentials.from_dict({
    'url': "<url>",
    'apikey': "<api_key>"
})

credentials_dict = credentials.to_dict()