---
name: inference-inf-create-api-key
title: Creating a service ID and API key for Red Hat AI Inference
description: 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.
last-updated: 2026-11-25
---

> ## Documentation Index
> The table of contents for this documentation set is at https://cloud.ibm.com/docs/inference?format=markdown
> The index for all IBM Cloud docs is at: https://cloud.ibm.com/docs/llms.txt
> Use these files to discover more information as needed.

# Creating a service ID and API key for Red Hat AI Inference
{: #inf-create-api-key}

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.
{: shortdesc}

To learn more about service IDs and service ID API keys, see [Creating and working with service IDs](https://cloud.ibm.com/docs/iam?topic=iam-serviceids&format=markdown) and [Managing service ID API keys](https://cloud.ibm.com/docs/iam?topic=iam-serviceidapikeys&format=markdown).

You can also authenticate with a user API key. For more information, see [Managing user API keys](https://cloud.ibm.com/docs/iam?topic=iam-userapikey&format=markdown).

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.
{: tip}

## Before you begin
{: #inf-create-api-key-prereqs}

* Create a Pay-As-You-Go or Subscription IBM Cloud account. Trial accounts are not supported. For more information or to upgrade your account, see [Account types](https://cloud.ibm.com/docs/account?topic=account-accounts-types&format=markdown).

* Create [a Red Hat AI Inference project](https://cloud.ibm.com/docs/inference?topic=inference-project&format=markdown).

* Download and install the [IBM Cloud CLI](https://cloud.ibm.com/docs/cli?topic=cli-getting-started&format=markdown).{: cli}

## Creating a service ID and API key from your project
{: #inf-create-api-key-project-ui}
{: ui}

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](https://cloud.ibm.com/inference/projects){: external} page, and select your project.
1. In the **Using the API** section, click **Create API key**.
1. Click **Next**, and select **This project only** to restrict access to the current project.
1. Click **Create**.
1. 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)
{: #inf-create-api-key-iam}
{: ui}

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
{: #inf-create-api-key-sid-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](https://cloud.ibm.com/iam/serviceids){: external}** and click **Create**.

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

1. From the service ID page, click **Assign access**.

1. Select **Red Hat AI Inference** as the service.

1. Within **Resources**, select **Specific resources** and choose your project.

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

1. Review the access summary and click **Assign**.

### Creating a service ID API key in IAM
{: #inf-create-api-key-key-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**.

1. Click **Create** and enter a name for your API key.

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

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

1. Click **Create**.

1. 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
{: #inf-create-api-key-cli-steps}
{: cli}

1. Create a service ID:

   ```sh
   ibmcloud iam service-id-create sample-sid
   ```
   {: pre}

1. 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:

   ```sh
   ibmcloud resource service-instance SERVICE_INSTANCE_NAME --id
   ```
   {: pre}

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

   ```sh
   ibmcloud resource service-instances --service-name instructlab
   ```
   {: pre}

1. 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:

   ```sh
   ibmcloud iam service-policy-create sample-sid --roles Writer --service-name instructlab --attributes "serviceInstance=SERVICE_INSTANCE_ID"
   ```
   {: pre}

   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:

   ```sh
   ibmcloud iam service-policy-create sample-sid --roles Writer --service-name instructlab
   ```
   {: pre}

1. Create a service ID API key:

   ```sh
   ibmcloud iam service-api-key-create sample-sid-key sample-sid
   ```
   {: pre}

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

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

   ```sh
   ibmcloud iam service-api-key-create sample-sid-key sample-sid --file FILE_PATH
   ```
   {: pre}

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

   ```sh
   ibmcloud iam service-api-key-create sample-sid-key sample-sid --output json
   ```
   {: pre}

## Creating a service ID and API key by using the API
{: #inf-create-api-key-api}
{: api}

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

* [Creating a service ID](https://cloud.ibm.com/docs/iam?topic=iam-serviceids&interface=api&format=markdown)
* [Creating a service ID API key](https://cloud.ibm.com/docs/iam?topic=iam-serviceidapikeys&interface=api&format=markdown)
* [IAM Identity Services API reference](https://cloud.ibm.com/docs/apis/iam-identity-token-api)
* [IAM Policy Management API reference](https://cloud.ibm.com/docs/apis/iam-policy-management#create-policy)

## Next steps
{: #inf-create-api-key-next-steps}

* See [Authenticating to the API](https://cloud.ibm.com/docs/inference?topic=inference-inf-auth&format=markdown) to use your API key or retrieve a bearer token.
* See [Listing models](https://cloud.ibm.com/docs/inference?topic=inference-inf-list-models&format=markdown) to explore available models.
* See [Working with chat completions](https://cloud.ibm.com/docs/inference?topic=inference-inf-chat-completions&format=markdown) to generate responses.
* See [Managing IAM access](https://cloud.ibm.com/docs/inference?topic=inference-iam&format=markdown) to configure roles and permissions.