dev.clore.ai
  • Getting Started
  • Introduction to Clore API
    • API Key Management
    • Transaction Processing with Clore Coin
    • RESTful Protocols in Clore
  • Marketplace Automation and Resource Optimization
    • Automated Spot Price Adjustment for Cost Optimization
    • Automated Server Retrieval and Analysis
    • Spot Price Optimization
    • Predictive Market Analytics
  • Server Management and Configuration
    • Bulk Server Onboarding and Dynamic Pricing Configuration
  • Dynamic Pricing and Profit Maximization
    • Dynamic Pricing Adjustments Based on Server Profitability
    • Automated Price Adjustment Based on Market Demand
    • Automated Spot Rental Based on Price Thresholds
  • Rental Strategies and Arbitrage
  • Monitoring and Notifications
    • Automated Monitoring and Notification of Rental Status
    • Automated Alert System for Low Server Utilization
    • Automated Retrieval and Analysis of Available Servers on the Marketplace
  • Security and Compliance
  • UI Automation and Visualization
  • API Performance Optimization
  • Community Extensions and Integrations
  • Advanced Data Processing and Analysis
  • Scalability and Infrastructure Management
  • Machine Learning and AI Integrations
    • Integrating ML Models into Server Operations
  • Developer Tools and SDKs
    • Setting Up the Clore Developer Toolkit
    • Using Clore SDK for Rapid Prototyping
  • Billing, Accounting, and Financial Reporting
  • Workflow Automation and Scripting
  • Multi-Cloud and Hybrid Cloud Integrations
  • Security Monitoring and Incident Management
  • Blockchain Interactions and Smart Contracts
  • Resource Optimization and Cost-Saving Techniques
Powered by GitBook
On this page

Introduction to Clore API

NextAPI Key Management

Last updated 6 months ago

Overview

The Clore API provides developers with powerful tools to manage GPU resources, automate workflows, monitor server status, and handle financial transactions on the Clore platform. This API allows you to interact programmatically with the Clore Marketplace, enabling advanced control over rentals, pricing, server configurations, and more.

In this introductory article, we will cover:

  • Setting up access to the Clore API

  • Authentication process

  • Basic API requests and response formats

  • Example use cases with code snippets


1. Getting Started: Setting Up Your API Access

To begin working with the Clore API, you need an API key, which acts as an authentication token to securely interact with the API. Follow these steps:

  1. Obtain Your API Key

    • Visit and create an account if you haven’t already.

    • Navigate to the API section in your account settings.

    • Generate a new API key, ensuring to save it securely as it will grant access to your resources.

  2. Setting Up the Authorization Header The Clore API requires each request to include an authentication header. Here’s how to structure it:

    headers = {
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json"
    }

2. Making Your First API Call

Let’s start with a simple request to check your wallet balance using the /wallets endpoint. This endpoint returns a list of wallets associated with your account, including balances and other details.

Example Code: Fetching Wallet Balance

import requests

# Define the API URL and headers
url = "https://api.clore.ai/v1/wallets"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}

# Make the request
response = requests.get(url, headers=headers)

# Print the result
if response.status_code == 200:
    print("Wallets:", response.json())
else:
    print("Error:", response.status_code, response.text)

Expected Response:

{
  "code": 0,
  "wallets": [
    {
      "name": "bitcoin",
      "deposit": "tb1q6erw7v02t7hakgmlcl4wfnlykzqj05alndruwr",
      "balance": 0.00153176,
      "withdrawal_fee": 0.0001
    }
  ]
}

3. Exploring Core Endpoints

a) Listing Servers Available for Rent

The /marketplace endpoint provides details on all available servers in the Clore Marketplace, including specifications, rental prices, and availability status.

Example Code: Retrieving Marketplace Data

# Define the marketplace endpoint URL
url = "https://api.clore.ai/v1/marketplace"

# Make the request to fetch marketplace data
response = requests.get(url, headers=headers)

# Print the data received
if response.status_code == 200:
    print("Marketplace Servers:", response.json())
else:
    print("Error:", response.status_code, response.text)

4. Working with Server Configurations

Use the /server_config endpoint to retrieve configuration details of a specific server you own.

Example Code: Fetching Server Configuration

import json

# Define the server configuration endpoint and data
url = "https://api.clore.ai/v1/server_config"
data = {
    "server_name": "YourServerName"
}

# Make the request to get server configuration
response = requests.get(url, headers=headers, data=json.dumps(data))

# Print server configuration details
if response.status_code == 200:
    print("Server Config:", response.json())
else:
    print("Error:", response.status_code, response.text)

5. Error Handling and Response Codes

The Clore API returns different status codes to indicate success or failure:

  • 0 - Normal

  • 1 - Database Error

  • 2 - Invalid Input Data

  • 3 - Invalid API Token

  • 4 - Invalid Endpoint

  • 5 - Exceeded request limit (1 request/second)

In your code, it's essential to handle these response codes for robust error management. Here's a basic example:

# Error handling example
if response.status_code == 200:
    data = response.json()
    if data.get("code") == 0:
        print("Operation successful:", data)
    else:
        print("API Error:", data.get("code"), data.get("message", "Unknown error"))
else:
    print("HTTP Error:", response.status_code, response.text)

6. Use Case: Automated Wallet Balance Monitoring

Suppose you want to automate the process of monitoring wallet balances and receive alerts if the balance drops below a specific threshold.

Example Code: Wallet Balance Alert

import time

def monitor_wallet_balance(threshold=0.0001):
    url = "https://api.clore.ai/v1/wallets"
    while True:
        response = requests.get(url, headers=headers)
        if response.status_code == 200:
            balance = response.json().get("wallets")[0].get("balance")
            if balance < threshold:
                print("Alert: Balance is below threshold!", balance)
            else:
                print("Current Balance:", balance)
        else:
            print("Error:", response.status_code, response.text)
        # Wait 10 minutes before next check
        time.sleep(600)

# Set a threshold and start monitoring
monitor_wallet_balance(0.0005)

7. Conclusion

This introductory guide has provided a foundational understanding of Clore API, covering basic requests, authentication, and essential endpoints. In the following articles, we will delve deeper into more complex use cases, including automated pricing adjustments, server configuration management, and dynamic resource allocation using Clore’s robust API capabilities.

Clore Wallet