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.
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.
4. In the General section, specify the API key name. Optionally, add a description.
5. In the Inference instances dropdown, select one or more deployments for which this key will be required for authentication.
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.
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.
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:
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)
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.
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.
A new page with the key overview will open. To check a particular functionality, navigate to the relevant tab.
In this tab, you can update the key name and description.
In this tab, you can add or remove deployments where this API key will be required to authenticate.
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.
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.
5. Confirm your action by clicking Delete API key.
Your API key has been successfully removed.
Was this article helpful?