fetch-logo
ConceptsConceptsGuidesGuidesExamplesExamplesReferencesReferencesAPIsAPIs
GitHub (opens in a new tab)
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
        • Introduction
        • Script to add secret to agent
        • Steps to add secret to Agent using API
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
Guides
APIs
Secret Management APIs

Adding Secret to Agents using Agentverse APIs

Introduction

This guide provides details on how to use the Agentverse hosting APIs ↗️ 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. Before you begin, ensure you satisfy the following pre-requisites:

  • Python version greater than 3.9 and less than 3.11.
  • The requests library installed. You can install it using pip install requests.
  • Agentverse ↗️ (opens in a new tab) credentials.

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

Let's explore the script for this example!

Script to add secret to agent

  1. Create a Python script and name it agent-secret.py using: touch agent-secret.py

  2. Within the script have just created, import the requests library:

    # Importing libraries
    import requests
  3. Define the token variable with your Fauna access token:

    # Decode the refresh token
    token = 'Bearer fauna_access_token'
  4. Now, input the agent's address, the name for the secret, and the value of the secret:

    # 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:  ")
  5. Create the payload for the POST request to add the secret:

    # Create Payload for post request
    data = {
        'address': address,
        'name': name,
        'secret': secret
    }
  6. Send the POST request to the Agentverse API to add the secret:

    # Post request to add secret to agent
    response_agent = requests.post("https://agentverse.ai/v1/hosting/secrets", json=data, headers={"Authorization": token})
  7. Check if the response status code is 200 (success) and print an appropriate message:

    # 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}")

The full script should look as follows:

agent-secret.py
# 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 th directory where agent-secret.py script is located using your 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

  • 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?

Agents and Functions creation APIsHow to convert native FET to and from ERC-20 FET
footer-logo

Main website

Integrations

Events

We’re hiring!

Twitter (opens in a new tab)Telegram (opens in a new tab)Discord (opens in a new tab)GitHub (opens in a new tab)Youtube (opens in a new tab)LinkedIn (opens in a new tab)Reddit (opens in a new tab)
Sign up for developer updates