0
$\begingroup$

I'm trying to use QiskitRuntimeService() and start a session to find the expectation value of some operator but I keep getting this error:

ApiException: Error: Provided API key could not be found., Code: 400.

The line that gives me the error is:

service = QiskitRuntimeService()

How can I fix it?

$\endgroup$

1 Answer 1

0
$\begingroup$

You have to initialize your account before you can start using Qiskit Runtime. If you don't have the credentials saved in your disk, you can initialize a QiskitRuntimeService instance as follows:

from qiskit_ibm_runtime import QiskitRuntimeService

# Save an IBM Cloud account on disk
token = '***'  # <== Use your token here
QiskitRuntimeService.save_account(channel="ibm_quantum", token=token)

You can find the token in your IBM Quantum account page.

If the error keeps happening, try to delete the saved account from disk at first then save it again:

QiskitRuntimeService.delete_account()
QiskitRuntimeService.save_account(channel="ibm_quantum", token=token, overwrite=True)

Once the credentials are saved, you can initialize the QiskitRuntimeService instance without passing any parameters:

# Read default credentials from disk
service = QiskitRuntimeService()

For more details see here.

$\endgroup$
7
  • $\begingroup$ I already did that, but it still won't work. I also tried to regenerate my token but I got the same error every time. $\endgroup$
    – user184655
    Mar 16, 2023 at 19:43
  • $\begingroup$ Did you try to add overwrite=True when calling with the new token? $\endgroup$ Mar 16, 2023 at 20:28
  • $\begingroup$ Yes, I did that too. $\endgroup$
    – user184655
    Mar 17, 2023 at 2:01
  • $\begingroup$ I actually get two different error. One of them is the one I mentioned and the other error is: IBMNotAuthorizedError: '401 Client Error: Unauthorized for url: auth.quantum-computing.ibm.com/api/users/loginWithToken. Login failed., Error code: 3446.' $\endgroup$
    – user184655
    Mar 17, 2023 at 3:35
  • $\begingroup$ Try to delete the saved account from disk at first: QiskitRuntimeService.delete_account(). $\endgroup$ Mar 17, 2023 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.