Skip to main content
IBM Quantum Platform

Initialize the service in an untrusted environment

Follow these instructions if you are working with IBM Cloud or the IBM Qiskit Runtime REST API in an untrusted environment, such as a public computer.

Avoid executing code on an untrusted machine or an external cloud Python environment to minimize security risks. If you must use an untrusted environment (on, for example, a shared or public computer), change your API key after each use by deleting it on the API keys page and creating a new one.

Caution

Protect your API key! Never include your key in source code, Python script, or notebook file. When sharing code with others, ensure that your API key is not embedded directly within the Python script. Instead, share the script without the token and provide instructions for securely setting it up.

If you accidentally share your key with someone or include it in version control like Git, immediately revoke your key by following the Deleting an API key topic on IBM Cloud.


Authenticate to IBM Cloud in an untrusted environment

To initialize the service in this situation, use code like the following:

from qiskit_ibm_runtime import QiskitRuntimeService
 
service = QiskitRuntimeService(
  # Delete your key on the API keys page after entering this code:
  token="<IBM Cloud API key>",
  # Optionally specify an instance to use
  instance="<IBM Cloud CRN or instance name>"
  )

Authenticate to the REST API in an untrusted environment

Follow these steps to use your API key directly to authenticate to the Qiskit Runtime REST API.

  1. Authenticate requests to the Qiskit Runtime REST API by including the CRN and bearer token to the request's headers.
# Refresh your API key on the dashboard after using the code as follows:
api_key = "<your-key>"
  1. Change your API key after each use by following the Deleting an API key instructions on IBM Cloud.

Next steps

Recommendations
Was this page helpful?
Report a bug or request content on GitHub.