IBM Support

Entering your API key and setting the CPLEX_STUDIO_KEY environment variable

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:

  1. Use the Window > Preferences > OPL menu and enter your API key in the Engine API key field.
 

For Mac or Linux:

  1. 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).
  2. 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:

  1. 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"
  2. Restart your machine after you have set the key.
 

For Mac or Linux:

  1. 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).
  2. 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
  3. Restart your machine.
 

[{"Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSSA5P","label":"IBM ILOG CPLEX Optimization Studio"},"ARM Category":[{"code":"a8m0z000000bri2AAA","label":"APIs"}],"ARM Case Number":"","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"12.10.0;12.8.0;12.9.0;20.1.0"},{"Product":{"code":"SSSA5P","label":"IBM ILOG CPLEX Optimization Studio"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":" ","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"},{"code":"PF022","label":"OS X"}],"Version":"","Edition":"All Editions","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
13 January 2021

UID

swg22008948