Important:

IBM Cloud Pak® for Data Version 4.8 will reach end of support (EOS) on 31 July, 2025. For more information, see the Discontinuance of service announcement for IBM Cloud Pak for Data Version 4.X.
Upgrade to IBM Software Hub Version 5.1 before IBM Cloud Pak for Data Version 4.8 reaches end of support. For more information, see Upgrading from IBM Cloud Pak for Data Version 4.8 to IBM Software Hub Version 5.1.

Authenticating for programmatic access to a project or space

To work with foundation models in IBM watsonx.ai programmatically, you must authenticate and identify your project or deployment space.

Credentials

You can authenticate API requests submitted from a notebook by using different methods. For more information about the supported methods, see Authentication.

To create credentials by using an API key, complete the following steps:

  1. Create a platform API key from the web client. For more information, see Generating API keys.

  2. Get the hostname for the Cloud Pak for Data cluster:

    oc get route cpd -n ${PROJECT_CPD_INST_OPERANDS} -ojsonpath='{.spec.host}'
    
    Tip:

    Another way to find the hostname is to open the Prompt Lab, and then click the View code icon </> to see the cURL command that is generated for the request. The segment of the request before /ml is the cluster hostname.

  3. Construct a credentials object that has the following information:

    • API key
    • Hostname for your service instance
    • Your user name
    • Cloud Pak for Data version

The following sample code snippet shows how you use an API key for authentication when using the Python library.

my_credentials = {
  "apikey"      : "gitk8kFqds1Q4kzbvKmI8ezBV1NPWe24MJ53pCBC",
  "url"         : "https://cpd-cpd-instance.apps.example.com",
  "username"    : "jdoe",
  "version"     : "4.8",
  "instance_id" : "openshift"
}

Project or deployment space details

The project ID or deployment space ID that is associated with the foundation model that you want to work with is required in Python library requests and in the data payload for most of the API methods.

The project must have an instance of Watson Machine Learning associated with it. The Watson Machine Learning service hosts the deployed watsonx.ai foundation models.

To get the ID of a project, complete the following steps:

  1. From your project, click the Manage tab.
  2. Copy the project ID from the Details section of the General page.

To get the ID of a deployment space, complete the following steps:

  1. From your deployment, click the Manage tab.
  2. Copy the space GUID from the Details section of the General page.

Parent topic: Coding genertaive AI solutions