API Key Management
Description: The following interfaces are used to manage API Keys for the MOI workspace. After successfully obtaining or creating an API Key, the returned moi-key should be passed in the Header when calling other MOI business APIs for authentication.
Steps to obtain an API KEY: After logging into the GenAI workspace platform, click on the user avatar in the top right corner of the page, and select the "API Management" option from the dropdown menu to view, obtain, or update your API keys.
Create API Key
POST /user/me/api-key
Description: Creates a new API Key (moi-key) for the current user.
Header Parameters:
| Parameter Name | Type | Required | Description |
|---|---|---|---|
access-token |
string | Yes | Account authentication token |
uid |
string | Yes | Account ID |
Response Parameters:
| Parameter Name | Type | Description |
|---|---|---|
key |
string | The generated API Key (moi-key) |
created_at |
string | Creation time |
request_id |
string | Request ID |
Example (Python):
import requests
import json
# Assume access_token and uid have been obtained via the login interface
access_token = "YOUR_ACCESS_TOKEN"
uid = "YOUR_USER_ID"
api_endpoint = "https://freetier-01.cn-hangzhou.cluster.matrixonecloud.cn"
url = f"{api_endpoint}/user/me/api-key"
headers = {
"access-token": access_token,
"uid": uid,
"Content-Type": "application/json",
"Accept": "application/json"
}
response = requests.post(url, headers=headers, json={})
print("Status Code:", response.status_code)
if response.status_code == 200:
try:
response_data = response.json()
print("Response Body (new moi-key details):", json.dumps(response_data, indent=4, ensure_ascii=False))
new_moi_key = response_data.get("data", {}).get("key")
if new_moi_key:
print(f"Successfully created new moi-key: {new_moi_key}")
else:
print("New moi-key not found in response.")
except json.JSONDecodeError:
print("Error decoding JSON from response:", response.text)
else:
print("Error Response Body:", response.text)
Example (JSON Response):
{
"code": "OK",
"msg": "OK",
"data": {
"key": "YOUR_NEW_MOI_KEY_STRING",
"created_at": "2023-05-29T08:06:42Z"
},
"request_id": "YOUR_REQUEST_ID"
}
Refresh API Key
POST /user/me/api-key/refresh
Description: Generates a new API Key (moi-key) for the current user. The old API Key will become invalid.
Header Parameters:
| Parameter Name | Type | Required | Description |
|---|---|---|---|
access-token |
string | Yes | Account authentication token |
uid |
string | Yes | Account ID |
Response Parameters (200 OK):
| Parameter Name | Type | Description |
|---|---|---|
key |
string | The newly generated API Key (moi-key) |
created_at |
string | New Key creation time |
request_id |
string | Request ID |
Example (Python):
import requests
import json
# Assume access_token and uid have been obtained via the login interface
access_token = "YOUR_ACCESS_TOKEN"
uid = "YOUR_USER_ID"
api_endpoint = "https://freetier-01.cn-hangzhou.cluster.matrixonecloud.cn"
url = f"{api_endpoint}/user/me/api-key/refresh"
headers = {
"access-token": access_token,
"uid": uid,
"Content-Type": "application/json",
"Accept": "application/json"
}
response = requests.post(url, headers=headers, json={})
print("Status Code:", response.status_code)
if response.status_code == 200:
try:
response_data = response.json()
print("Response Body (refreshed moi-key details):", json.dumps(response_data, indent=4, ensure_ascii=False))
refreshed_moi_key = response_data.get("data", {}).get("key")
if refreshed_moi_key:
print(f"Successfully refreshed moi-key: {refreshed_moi_key}")
else:
print("Refreshed moi-key not found in response.")
except json.JSONDecodeError:
print("Error decoding JSON from response:", response.text)
else:
print("Error Response Body:", response.text)
Example (JSON Response):
{
"code": "OK",
"msg": "OK",
"data": {
"key": "YOUR_REFRESHED_MOI_KEY_STRING",
"created_at": "2023-05-29T08:10:00Z"
},
"request_id": "YOUR_REQUEST_ID"
}