Question & Answer
Question
Why do I need an API key and how do I set the CPLEX_STUDIO_KEY environment variable?
Answer
When you purchase a ‘Development Authorized User Monthly' subscription on Marketplace (https://www.ibm.com/us-en/marketplace/ibm-ilog-cplex/purchase#product-header-top), you receive an email that contains your API key.
The API key unlocks the limitations on the size of models that the engines can solve. At the start of a solve, if a key was specified, the engine connects to an IBM server to check the validity of the key. It caches the result so as to not have to contact the server too frequently.
Depending on the way you use the product, you can set the key in two different ways (the details of how to do so are given in the rest of this note):
- If you only use the Studio IDE (in other words, you do not use any of the APIs, nor do you use one of the two Interactive programs), you can set the API key in Studio.
- If you use any API (C, C++, .NET, Java, or Python), one of the Interactive programs, or the MATLAB or AMPL connectors for CPLEX, you must create the CPLEX_STUDIO_KEY environment variable with your key. Note that if you set the CPLEX_STUDIO_KEY environment variable, adding the key in the Studio is not then necessary.
To enter your API key in Studio:
For Windows:
- Use the Window > Preferences > OPL menu and enter your API key in the
Engine API key
field.
For Mac or Linux:
- First create the CPLEX_STUDIO_DIR1210 environment variable and set its value to your installation directory (by default this is /opt/ibm/ILOG/CPLEX_Studio_Community1210 on Linux, and /Applications/CPLEX_Studio_Community1210 on Mac).
- Use the Oplide > Preferences > OPL menu and enter your API key in the Engine API key field.
For all platforms, after entering your API key, close and reopen the IDE.
NOTE Please use the following names for the CPLEX_STUDIO_DIRnnn environment variable, according to your version of CPLEX Optimization Studio:
- V12.8: CPLEX_STUDIO_DIR128
- V12.9: CPLEX_STUDIO_DIR129
- V12.10: CPLEX_STUDIO_DIR1210
- V20.1: CPLEX_STUDIO_DIR201
To create the CPLEX_STUDIO_KEY environment variable:
This environment variable only needs to be set for the current user and not system-wide.
Use the following procedure and then restart your machine.
For Windows:
- To create the CPLEX_STUDIO_KEY environment variable, open a command prompt and enter the following, using the API key you received by email:
setx CPLEX_STUDIO_KEY "yourAPIkey" - Restart your machine after you have set the key.
For Mac or Linux:
- First create the CPLEX_STUDIO_DIR1210 environment variable and set its value to your installation directory (by default this is /opt/ibm/ILOG/CPLEX_Studio_Community1210 on Linux, and /Applications/CPLEX_Studio_Community1210 on Mac).
- Then create the CPLEX_STUDIO_KEY environment variable. One way to do this is to run the following command in a Terminal, using the API key you received by email:
echo "export CPLEX_STUDIO_KEY=yourAPIkey" >> .bash_profile - Restart your machine.
For more information see IBM ILOG CPLEX Optimization Studio V20.1.0 product documentation.
Was this topic helpful?
Document Information
Modified date:
13 January 2021
UID
swg22008948