Python SDK (clore-ai)

Complete API reference for the official clore-aiarrow-up-right Python SDK — the recommended way to interact with the Clore.ai GPU marketplace from Python and the command line.


Installation

pip install clore-ai

Requirements: Python 3.9+

📚 New to the SDK? Read Clore.ai Python SDK — Automate Your GPU Workflows in 5 Minutesarrow-up-right for a hands-on tutorial.

From source:

git clone https://gitlab.com/cloreai/clore-ai-sdk.git
cd clore-ai
pip install -e .

Authentication

The SDK resolves your API key in this order:

  1. Constructor argumentCloreAI(api_key="...")

  2. Environment variableCLORE_API_KEY

  3. Config file~/.clore/config.json (set via clore config set api_key YOUR_KEY)

Get your key from clore.aiarrow-up-right.


CloreAI — Synchronous Client

Constructor

Parameter
Type
Default
Description

api_key

str | None

None

Clore.ai API key. If omitted, reads CLORE_API_KEY env var or ~/.clore/config.json

base_url

str | None

https://api.clore.ai/v1

API base URL

timeout

float

30.0

Request timeout (seconds)

max_retries

int

3

Max retries on transient / rate-limit errors

Context manager support:


wallets()

Get all wallet balances for the authenticated account.

Returns: List[Wallet]

Raises: AuthError if no API key is set.

Example:


marketplace()

Browse available GPU servers. This is a public endpoint — no API key required.

Parameter
Type
Default
Description

gpu

str | None

None

Filter by GPU model substring (case-insensitive), e.g. "RTX 4090"

min_gpu_count

int | None

None

Minimum number of GPUs per server

min_ram_gb

float | None

None

Minimum RAM in GB

max_price_usd

float | None

None

Maximum price per hour in USD

available_only

bool

True

Only return servers not currently rented

Returns: List[MarketplaceServer]

Note: Filtering happens client-side. The API returns all servers; the SDK filters the results based on your criteria.

Example:


my_servers()

List servers you host on the Clore.ai marketplace.

Returns: List[MyServer]

Note: my_servers() returns MyServer objects, not MarketplaceServer. MyServer has a .status property that returns "Online", "Offline", "Disconnected", or "Not Working".

Raises: AuthError if no API key is set.

Example:


server_config()

Get the configuration for one of your hosted servers.

Parameter
Type
Description

server_name

str

Name of your server

Returns: ServerConfig

Example:


my_orders()

List your rental orders.

Parameter
Type
Default
Description

include_completed

bool

False

Also return completed/cancelled orders

Returns: List[Order]

Example:


create_order()

Create a new GPU rental order.

Parameter
Type
Description

server_id

int

Server ID from marketplace

image

str

Docker image, e.g. "cloreai/ubuntu22.04-cuda12"

type

"on-demand" | "spot"

Order type

currency

str

Payment currency: "bitcoin", "CLORE-Blockchain", etc.

ssh_password

str | None

SSH password for the instance

ssh_key

str | None

SSH public key (mutually exclusive with ssh_password)

ports

Dict[str, str] | None

Port mappings, e.g. {"22": "tcp", "8888": "http"}

env

Dict[str, str] | None

Environment variables

jupyter_token

str | None

Jupyter access token

command

str | None

Custom startup command

spot_price

float | None

Bid price for spot orders

required_price

float | None

Required price

autossh_entrypoint

str | None

Auto SSH entrypoint

Returns: Order

Raises: AuthError, InvalidInputError, RateLimitError

Rate limit: create_order has a special 5-second cooldown between calls, enforced by the built-in rate limiter.

Example:


cancel_order()

Cancel an active order.

Parameter
Type
Description

order_id

int

Order ID to cancel

issue

str | None

Optional cancellation reason

Returns: Dict[str, Any] — API response

Example:


spot_marketplace()

Get spot market data for a specific server.

Parameter
Type
Description

server_id

int

Server ID

Returns: SpotMarket — object with offers (list of SpotOffer), server info, and currency_rates_in_usd

Example:


set_spot_price()

Update the spot price for one of your orders.

Parameter
Type
Description

order_id

int

Active order ID

price

float

New spot bid price

Returns: Dict[str, Any]

Example:


set_server_settings()

Update settings for one of your hosted servers.

Parameter
Type
Description

name

str

Server name

availability

bool | None

Toggle availability on/off

mrl

int | None

Minimum rental length in hours

on_demand

float | None

On-demand price

spot

float | None

Spot price

Returns: Dict[str, Any]

Example:


close()

Close the underlying HTTP client. Called automatically when using the context manager.


AsyncCloreAI — Asynchronous Client

The async client mirrors every method of CloreAI but returns coroutines. It uses httpx.AsyncClient under the hood.

Constructor

Parameters are identical to CloreAI.

Methods

All methods have the same signatures as the sync client. Prefix calls with await:

Concurrent Operations

The main advantage of the async client is running multiple API calls in parallel:


Models

All models are Pydanticarrow-up-right BaseModel subclasses with extra="allow" (so they won't break when the API adds new fields) and populate_by_name=True.

Wallet

MarketplaceServer

Returned by marketplace(). Has a nested structure with specs, price, and rating sub-objects, plus convenience properties for easy access.

Note: Server is a backward-compatible alias for MarketplaceServer.

ServerSpecs

Nested under MarketplaceServer.specs.

ServerPrice

Nested under MarketplaceServer.price.

MyServer

Returned by my_servers(). Different from MarketplaceServer — represents servers you host.

ServerConfig

Returned by server_config().

Order

SpotMarket

Returned by spot_marketplace().

APIResponse


Exceptions

All exceptions inherit from CloreAPIError.

Hierarchy

CloreAPIError

Error Code Table

Code
Exception Class
Meaning

0

(success)

No error

1

DBError

Database / internal error

2

InvalidInputError

Invalid input parameters

3

AuthError

Authentication failed

4

InvalidEndpointError

Unknown endpoint

5

RateLimitError

Rate limit exceeded

6

FieldError

Error in a specific field (see response)

Handling Errors


Rate Limiter

The SDK includes a built-in RateLimiter that enforces:

  • 1 request/second for all endpoints (configurable via requests_per_second)

  • 5-second cooldown between create_order calls (configurable via create_order_delay)

  • Exponential backoff on rate-limit errors (code 5): starts at 1 s, doubles each retry up to max_retries

How It Works

The rate limiter is automatic — you don't need to configure anything. If you want to adjust:


Configuration

Environment Variables

Variable
Description

CLORE_API_KEY

API key (preferred over config file)

Config File (~/.clore/config.json)

Set via CLI:

Priority Order

  1. api_key passed to constructor

  2. CLORE_API_KEY environment variable

  3. ~/.clore/config.json


CLI Reference

The clore command-line tool is installed with the package. It uses Richarrow-up-right for formatted terminal output.

Commands

Command
Description

clore search

Search GPU marketplace

clore orders

List your orders

clore deploy <server_id>

Create a new order

clore cancel <order_id>

Cancel an order

clore wallets

Show wallet balances

clore servers

List your hosted servers

clore server-config <name>

Get server configuration

clore spot <server_id>

View spot market for a server

clore spot-price <order_id> <price>

Set spot price

clore ssh <order_id>

SSH into an order

clore config set <key> <value>

Set config value

clore config get <key>

Get config value

clore config show

Show all config

clore deploy

clore ssh


See Also

Last updated

Was this helpful?