Agent Secret API
Bookmark

Adding Secret to agent using Agentverse API

Introduction

This example provides details on how to use the hosting API to add a secret to an agent. Secrets are added to an agent to ensure they remain hidden from end users and to enhance security.

Prerequisites

  • Before you begin, ensure you have the following:

Steps to get API Tokens

  • Go to Profile section in Agentverse ↗️ (opens in a new tab).
  • Click on button + New API Key.
  • Give name to your API key.
  • Click on write for Access to all resources in Agentverse and click on Generate API Key

Script to add secret to agent

# Importing libraries
import requests
 
# Decode the refresh token
token = 'Bearer fauna_access_token'
 
# Take name of agent and secret details from user
address = input('Please enter address of agent to which you want to add the secret:  ')
name = input("Please enter name for your secret:  ")
secret = input("Please enter value for your secret:  ")
 
# Create Payload for post request
data = {
    'address': address,
    'name': name,
    'secret': secret
}
 
# Post request to add secret to agent
response_agent = requests.post("https://agentverse.ai/v1/hosting/secrets", json=data, headers={"Authorization": token})
 
 
# Check if the response code is 200
if response_agent.status_code == 200:
    print("Secret added successfully.")
else:
    print(f"Failed to add secret. Status code: {response_agent.status_code}")

Steps to add secret to agent using API

  • Navigate to directory where agent-secret script are located using terminal.
  • Open Agentverse ↗️ (opens in a new tab) and generate API keys.
  • Open script in editor and replace fauna_access_token.
  • Run agent-secret.py file using python agent-secret.py file.
  • Provide agent's address, secret name and secret value.
  • Try using secret name in script instead of value, for example APIKey in our case.

Expected Output

  • Provide details and response on basis of secret added or not to the agent in agentverse.

Was this page helpful?

Bookmark