Creating a service ID and API key for Red Hat AI Inference

API keys authenticate requests to the Red Hat AI Inference API. Using a service ID API key is recommended to manage and delegate access permissions.

To learn more about service IDs and service ID API keys, see Creating and working with service IDs and Managing service ID API keys.

You can also authenticate with a user API key. For more information, see Managing user API keys.

When you create the service ID, assign the Writer service access role to create chat completions. Assign the Reader service access role if you need only to view model information or read chat completions. Platform access roles are not required for API access.

Before you begin

Creating a service ID and API key from your project

A service ID manages access for applications and automated workflows. When you create a service ID directly within your project, the Writer service access role is automatically assigned so that you can create chat completions.

  1. Go to the Red Hat AI Inference projects page, and select your project.
  2. In the Using the API section, click Create API key.
  3. Click Next, and select This project only to restrict access to the current project.
  4. Click Create.
  5. Copy the API key and store it securely. The API key value cannot be displayed again.

Creating a service ID and API key in Identity and Access Management (IAM)

Alternatively, you can create the service ID and API key in the IBM Cloud console by using IAM.

Creating a service ID and assigning access in IAM

Create the service ID, then assign it access to your project.

  1. In the IBM Cloud console, go to Manage > Access (IAM) > Service IDs and click Create.

  2. Enter a name and description for your service ID, then click Create.

  3. From the service ID page, click Assign access.

  4. Select Red Hat AI Inference as the service.

  5. Within Resources, select Specific resources and choose your project.

  6. Within Roles and actions, select Writer as the service access role.

  7. Review the access summary and click Assign.

Creating a service ID API key in IAM

Now that your service ID has access to your project, create a service ID API key.

  1. From the service ID page, click API keys.

  2. Click Create and enter a name for your API key.

  3. For leaked key handling, select Disable the leaked key to automatically disable the key if it's detected as leaked.

  4. Set an expiration date for the key. Regular key rotation is recommended for security.

  5. Click Create.

  6. Copy the API key and save it in a secure location. The key cannot be viewed again.

Creating a service ID and API key by using the CLI

  1. Create a service ID:

    ibmcloud iam service-id-create sample-sid
    
  2. To assign the policy to a specific Red Hat AI Inference project, you need the project's service instance ID. To get the ID, run the following command, where SERVICE_INSTANCE_NAME is the name of your Red Hat AI Inference project:

    ibmcloud resource service-instance SERVICE_INSTANCE_NAME --id
    

    To list your service instances and their names, run the following command:

    ibmcloud resource service-instances --service-name instructlab
    
  3. Assign an access policy to the service ID.

    Example command to assign the Writer service access role to the service ID sample-sid for a specific Red Hat AI Inference project in the account. Replace SERVICE_INSTANCE_ID with the ID from the previous command:

    ibmcloud iam service-policy-create sample-sid --roles Writer --service-name instructlab --attributes "serviceInstance=SERVICE_INSTANCE_ID"
    

    Example command to assign the Writer service access role to the service ID sample-sid for all Red Hat AI Inference projects in the account:

    ibmcloud iam service-policy-create sample-sid --roles Writer --service-name instructlab
    
  4. Create a service ID API key:

    ibmcloud iam service-api-key-create sample-sid-key sample-sid
    

    The API key is shown only once when it is created. Copy the API key and save it in a secure location.

    To save the API key directly to a file when it is created, use the --file option:

    ibmcloud iam service-api-key-create sample-sid-key sample-sid --file FILE_PATH
    

    Alternatively, you can output the API key details in JSON format by using the --output json option:

    ibmcloud iam service-api-key-create sample-sid-key sample-sid --output json
    

Creating a service ID and API key by using the API

You can create and manage service IDs, API keys, and access policies programmatically by using the IAM APIs:

Next steps