Save your login credentials
If you are working in a trusted Python environment (such as on a personal laptop or workstation), you can use the save_account()
method to save your credentials locally, then use them to initialize the service.
- If you are using a public computer or other untrusted environment, follow the instructions in Initialize the service in an untrusted environment instead.
- Follow these instructions if you want to connect by using the REST API instead of using Qiskit.
- If necessary, use this information to configure your firewall to enable access to the IBM Quantum API endpoints.
Before you begin
- Ensure that you have an IBM Cloud account.
- Ensure you are working in an active Python environment with the Qiskit SDK and Qiskit Runtime installed.
- Activate the Python virtual environment and run Python in your virtual environment.
- Find your access credentials.
- Log in to IBM Quantum Platform with an IBMid or Google account.
- Make sure that the correct account and region are selected in the account switcher in the header.
- Find your API key. From the dashboard, create your API key, then copy it to a secure location so you can use it for authentication. Note that you can use the same API key to connect to any region.
- Optional: Find the instance you want to use from the Instances page. Hover over its CRN, click the icon to copy it, then save it in a secure location so you can use it to identify the instance.
Save your access credentials
Save your credentials by running the appropriate code once per account you want to save. After saving your credentials, load them by following the steps in Initialize the Qiskit Runtime service.
Save credentials that access a specific instance:
If you have multiple instances and want to easily tell Qiskit Runtime which instance to use, save credentials that include an instance CRN.
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(
token="<your-api-key>", # Use the 44-character API_KEY you created and saved from the IBM Quantum Platform Home dashboard
name="<account-name>", # Optional
instance="<IBM Cloud CRN or instance name>", # Optional
set_as_default=True, # Optional
overwrite=True, # Optional
)
Save credentials for automatic instance selection:
If you don't provide an instance CRN and pass these credentials to Qiskit Runtime, an appropriate instance will be chosen for you, based on the specified options.
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(
token="<your=api-key>", # Use the 44-character API_KEY you created and saved from the IBM Quantum Platform Home dashboard
name="<account-name>", # Optional
plans_preference="<plan_types", # Optional
region="<region>", # Optional
tags="<instance-tags>", # Optional
set_as_default=True, # Optional
overwrite=True, # Optional
)
Available options
token
: IBM Cloud API key. Your token is confidential. Do not share your token in public code.instance
: Optionally specify the instance to use through its IBM Cloud CRN or instance name.plans_preference
: Optionally set the types of plans to prioritize. This is ignored if the instance is specified. Available options areopen
,pay-as-you-go
,flex
,premium
, andon-prem
. Instances of a certain plan type are excluded if the plan name is not specified. For example, if [open
] is passed in, only Open Plan instances are available. This is ignored ifinstance
is specified.region
: Optionally set the region to use. Accepted values areus-east
andeu-de
. This is ignored ifinstance
is specified.tags
: Optionally specify the instance's tags. Accepts a list of tag name strings. This is ignored ifinstance
is specified.name
: Optionally name this set of account credentials.set_as_default
: Set the value toTrue
to save these as your default credentials. If you save only one account, it is automatically set as the default.overwrite
: Set this value toTrue
to update your default credentials.
Examples
Example 1
This example saves credentials for specific instances, which allow open and premium access. The open credentials are set as the default.
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(token="<API_TOKEN>", instance="<CRN_for_premium_instance>",
name="premium")
QiskitRuntimeService.save_account(token="<API_TOKEN>", instance="<CRN_for_open_instance>",
name="open", set_as_default=True)
Example 2
This example saves credentials for automatic instance selection. Qiskit Runtime will only look at premium instances in the EU region that are available to the account. These credentials become the new default.
QiskitRuntimeService.save_account(
token="your-api-key",
set_as_default=True,
overwrite = True,
# Set instance "filters" instead of specifying the instance:
region="eu-de",
plans_preference=["premium"]
)
Considerations
- If you are saving multiple accounts, use the
name
parameter to differentiate them. - Credentials are saved to
$HOME/.qiskit/qiskit-ibm.json
. Do not manually edit this file. - If you don't save your credentials, you must specify them every time you start a new session (instantiate the Qiskit Runtime service).
- If you manually specify your credentials, a saved account will not be used.
Next steps
- Initialize the Qiskit Runtime service in a trusted Python environment.
- Initialize the Qiskit Runtime service in an untrusted environment.
- View your available QPUs.
- Configure the Qiskit SDK locally.
- Follow the steps in Hello world to write and run a quantum program.
- Set up to use IBM Quantum Platform with REST API.
- Try a tutorial.