API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
Edge AI
Edge AI
Chosen image
Home/Edge AI/Inference at the Edge/Create and manage API keys

Create and manage API keys

Setting up API keys protects deployed AI models from unauthorized access.

You can add multiple API keys to a single deployment, and the same API key can be attached to multiple deployments.

Create an API key

You can create an API key in different ways: during AI model deployment, via a deployed AI model's settings, or on the API keys page. Here, we explain the latter approach.

To create an API key and add it to the deployment:

1. In the Gcore Customer Portal, navigate to Cloud > Inference at the Edge.

2. Click API keys.

3. Click Create API key.

API keys page with highlighted Add api key button

4. In the General section, specify the API key name. Optionally, add a description.

General section with key name and description

5. In the Inference instances dropdown, select one or more deployments for which this key will be required for authentication.

Inference instances section with instance dropdown

6. In the Expiration section, select for how long the key will be valid:

  • Never expire: The key will remain valid indefinitely.

  • Set an expiration date: After the specified date, the key will no longer grant access to the attached deployments. By default, the key expires at 00:00 UTC on the specified date.

Expiration section date options

7. Click Create.

8. Copy the key and save it locally.

9. Click OK, I’ve copied API Key.

The key has been successfully created.

Never share your API key with third parties. This might result in unauthorized access to your deployments.

Access a model using API key

To access an AI model where an API key was added as an authorization method, you must include that API key in your cURL request.

Add your API key to the request header:

curl --location 'YOUR_MODEL_ENDPOINT' \ --header 'x-api-key: YOUR_API_KEY'

The following examples demonstrate how to authenticate to an OpenAI model deployed on inference nodes with the API key.

Example 1

client = OpenAI( 
    base_url="<Inference Endpoint>/v1", 
    api_key="notused", 
    default_headers={ 
        "x-api-Key": "<APIKEY>", 
    } 
) 
completion = client.chat.completions.create( 
  model="<ModelName>", 
  messages=[ 
    {"role": "user", "content": "Hello!"} 
  ] 
) 
print(completion.choices[0].message)

Example 2

from typing import override
  
from openai import OpenAI

class GcoreCompatibleOpenAI(OpenAI):
    @property
    @override
    def auth_headers(self) -> dict[str, str]:
        api_key = self.api_key
        return {"x-api-Key": api_key}
client = GcoreCompatibleOpenAI(
    base_url="<Inference Endpoint>/v1",
    api_key="<APIKEY>",
)
completion = client.chat.completions.create(
  model="<ModelName>",
  messages=[
    {"role": "user", "content": "Hello!"}
  ]
)
print(completion.choices[0].message)

Manage API keys

You can view detailed information about an API key, change the deployments where it's used for authentication, modify the expiration date, or delete the key from the Gcore Customer Portal.

Edit API key

1. In the Gcore Customer Portal, navigate to Cloud > Inference at the Edge.

2. Click API keys.

3. Find the key you want to edit and click the three-dot icon to open the settings menu.

4. Click Edit.

api key settings with highlighted edit button

A new page with the key overview will open. To check a particular functionality, navigate to the relevant tab.

General

In this tab, you can update the key name and description.

General tab with options to edit key name and description

Inference instances

In this tab, you can add or remove deployments where this API key will be required to authenticate.

Instances tab with dropdpwn tp add instances

Expiration

If your key is close to expiring, you can modify the expiry date on this tab, ensuring that the key remains a valid authentication method. Alternatively, you can choose the option Never expire to keep the key valid indefinitely.

Expiration tab with options to change expiration date

Delete API key

1. In the Gcore Customer Portal, navigate to Cloud > AI infrastructure.

2. Open the Inference at the Edge page and click API keys.

3. Find the key you want to remove and click the three-dot icon to open the settings menu.

4. Click Delete.

api key settings with highlighted delete button

5. Confirm your action by clicking Delete API key.

Delete key confirmation dialog

Your API key has been successfully removed.

Was this article helpful?