Set Up API Authentication for OCI

Set up OCI API authentication on your local environment so you can connect to your OCI tenancy.

Get the Configuration File Information

You can use the Console to generate the private/public key pair for yourself. If you already have a key pair, you can select to upload the public key. When you use the Console to add the key pair, the Console also generates a configuration file preview snippet for you.

  1. Gather the following information from your tenancy.
  2. In the Console's main menu, select your profile icon.
  3. Select User Settings.
  4. From the Resources list, select API keys.
  5. Select Add API key.
  6. Generate or provide keys as instructed in the dialog.
    Important

    If you generate keys, save the keys in a secure location. If you lose the keys, they can't be re-created, you must create new keys from scratch.
  7. Select Add.
  8. A dialog displays the configuration settings. Copy the configuration information into the config file. Save the file
  9. If no region is provided use us-chicago-1 or a region with Generative AI Agents.

If you need help, see Required Keys and OCIDs for API signing.

Create a Local Configuration File

  1. From the terminal, go to your home directory.
  2. Create a .oci directory.
  3. Change into the .oci directory.
  4. Enter the following command: touch config.
  5. Paste the API key configuration data that you copied in the previous section into the config file.

    Example config file.

    [DEFAULT]
    user=<ocid1.user.oc1..xxx>
    fingerprint=<xx:xx:xx:xx>
    tenancy=<ocid1.tenancy.oc1..xxx>
    region=us-chicago-1
    key_file=<path-to-private-key.pem>       

    This configuration is for the Default profile mentioned with [Default].

Install OCI CLI

  1. Install the OCI CLI and Python SDK using pip:
    pip install oci-cli

    All the required libraries are installed.

  2. Verify that the OCI CLI is installed. Enter the following command.
    oci

    The command lists the available commands for the CLI.

  3. Verify that the configuration file works.
    oci os ns get

    This command gets the namespace of your tenancy.

    oci iam region list

    This command lists the available regions in your tenancy.