SDK для Python (clore-ai)

The clore-ai package is the official Python SDK for the Clore.aiarrow-up-right GPU marketplace. It wraps the entire REST API into a clean, type-safe interface with built-in rate limiting, automatic retries, and structured error handling — so you can focus on renting GPUs, not on HTTP plumbing.


Installation

pip install clore-ai

Requirements: Python 3.9+

The package installs both the Python SDK and the clore CLI.


Authentication

Get your API key from the Clore.ai dashboardarrow-up-rightAPI section.

export CLORE_API_KEY=your_api_key_here

The SDK reads CLORE_API_KEY automatically — no code changes needed.

Option 2: CLI config file

clore config set api_key YOUR_API_KEY

This stores the key in ~/.clore/config.json.

Option 3: Pass directly in code

⚠️ Important: The Clore.ai API uses the auth header for authentication, not Authorization: Bearer. The SDK handles this automatically.


Quick Start


Sync Client (CloreAI)

Constructor

The client supports context managers for automatic cleanup:


wallets()

Get your wallet balances and deposit addresses.

Returns: List[Wallet]

Field
Type
Description

name

str

Currency name (e.g. "bitcoin", "CLORE-Blockchain", "USD-Blockchain")

balance

float | None

Current balance

deposit

str | None

Deposit address

withdrawal_fee

float | None

Withdrawal fee


marketplace()

Search the GPU marketplace with optional client-side filters.

Parameters:

Parameter
Type
Default
Description

gpu

str | None

None

Filter by GPU model (case-insensitive substring match)

min_gpu_count

int | None

None

Minimum number of GPUs

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 that are available to rent

Returns: List[MarketplaceServer]

Each MarketplaceServer provides convenient properties for the most common fields, plus access to the full nested data:

Property
Type
Description

id

int

Unique server ID

gpu_model

str | None

Primary GPU description (e.g. "1x NVIDIA GeForce RTX 4090")

gpu_count

int

Number of GPUs (from gpu_array)

ram_gb

float | None

RAM in GB

price_usd

float | None

On-demand price in USD

spot_price_usd

float | None

Spot price in USD

available

bool

Whether the server is available (not rented)

location

str | None

Country code from network specs

For advanced use cases, you can access the full nested structure:

Field
Type
Description

specs

ServerSpecs | None

Full hardware specs (specs.gpu, specs.ram, specs.cpu, specs.disk, specs.net, etc.)

price

ServerPrice | None

Full price object (price.usd.on_demand_usd, price.usd.spot, price.on_demand, etc.)

rented

bool | None

Whether the server is currently rented

reliability

float | None

Server reliability score

rating

ServerRating | None

Server rating (rating.avg, rating.cnt)

Note: The marketplace() endpoint is public — it works without an API key.


my_servers()

List servers you are providing to the Clore.ai marketplace.

Returns: List[MyServer]

Property
Type
Description

id

int

Server ID

name

str | None

Server name

gpu_model

str | None

Primary GPU description

ram_gb

float | None

RAM in GB

status

str

Human-readable status: "Online", "Offline", "Disconnected", or "Not Working"

connected

bool | None

Whether the server is connected

online

bool | None

Whether the server is online

visibility

str | None

"public" or "private"


server_config(server_name)

Get the configuration of a specific server you host.

Parameters:

Parameter
Type
Description

server_name

str

Name of the server

Returns: ServerConfig

Property
Type
Description

name

str | None

Server name

gpu_model

str | None

Primary GPU description

mrl

int | None

Minimum rental length in hours

on_demand_price

float | None

First available on-demand USD price

spot_price

float | None

First available spot USD price

specs

ServerSpecs | None

Full hardware specifications

connected

bool | None

Whether the server is connected

visibility

str | None

"public" or "private"


my_orders(include_completed)

Get your current orders, optionally including completed/expired ones.

Parameters:

Parameter
Type
Default
Description

include_completed

bool

False

Include completed/expired orders

Returns: List[Order]

Field
Type
Description

id

int

Unique order ID

server_id

int | None

Server ID

type

str

"on-demand" or "spot"

status

str | None

Order status

image

str | None

Docker image

currency

str | None

Payment currency

price

float | None

Order price per day

pub_cluster

str | None

Public hostname/IP for access

tcp_ports

dict | None

TCP port mappings


spot_marketplace(server_id)

View spot market offers for a specific server.

Parameters:

Parameter
Type
Description

server_id

int

Server ID to check

Returns: SpotMarket

Field
Type
Description

offers

List[SpotOffer] | None

List of spot offers (order_id, price, server_id)

server

SpotServerInfo | None

Server info (min pricing, visibility, online status)

currency_rates_in_usd

Dict[str, float] | None

Currency exchange rates in USD


create_order(...)

Create a new on-demand or spot order. This is how you rent a GPU.

On-demand order

Spot order

Parameters:

Parameter
Type
Required
Description

server_id

int

Yes

Server ID to rent

image

str

Yes

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

type

str

Yes

"on-demand" or "spot"

currency

str

Yes

Payment currency (e.g. "bitcoin")

ssh_password

str

No

SSH password (alphanumeric, max 32 chars)

ssh_key

str

No

SSH public key (max 3072 chars)

ports

dict

No

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

env

dict

No

Environment variables

jupyter_token

str

No

Jupyter notebook token (max 32 chars)

command

str

No

Shell command to run after container start

spot_price

float

Spot only

Price per day for spot orders

required_price

float

No

Lock in a specific price (on-demand only)

autossh_entrypoint

str

No

Use Clore.ai SSH entrypoint

Returns: Order

Rate limit: create_order has a special 5-second cooldown between calls. The SDK enforces this automatically.


cancel_order(order_id, issue)

Cancel an active order or spot offer. Optionally report an issue with the server.

Parameters:

Parameter
Type
Required
Description

order_id

int

Yes

Order ID to cancel

issue

str

No

Cancellation reason / issue report (max 2048 chars)

Returns: Dict[str, Any]


set_server_settings(...)

Update settings for a server you host on the marketplace.

Parameters:

Parameter
Type
Required
Description

name

str

Yes

Server name

availability

bool

No

Whether the server can be rented

mrl

int

No

Minimum rental length in hours

on_demand

float

No

On-demand price per day

spot

float

No

Minimum spot price per day

Returns: Dict[str, Any]


set_spot_price(order_id, price)

Update the price on your spot market offer.

Parameters:

Parameter
Type
Description

order_id

int

Spot order/offer ID

price

float

New price per day

Returns: Dict[str, Any]

Note: You can only lower spot prices once every 600 seconds, and by a limited step size. The API returns code: 6 with details if you exceed these limits.


Async Client (AsyncCloreAI)

The AsyncCloreAI client provides the same methods as CloreAI, but all return coroutines. Use it when you need concurrent API calls or are working within an async application.

Basic usage

Concurrent operations

Run multiple API calls in parallel with asyncio.gather:

Available methods

AsyncCloreAI supports all the same methods as CloreAI:

Method
Description

await wallets()

Get wallet balances

await marketplace(...)

Search marketplace

await my_servers()

List your hosted servers

await server_config(name)

Get server configuration

await my_orders(...)

List your orders

await spot_marketplace(server_id)

Get spot market offers

await create_order(...)

Create a new order

await cancel_order(...)

Cancel an order

await set_server_settings(...)

Update server settings

await set_spot_price(...)

Update spot price


Error Handling

The SDK provides structured exception classes for every API error code.

Коды ошибок

Код
Исключение
Description

0

Успех

1

DBError

Ошибка базы данных

2

InvalidInputError

Неверные входные данные

3

AuthError

Недействительный API-токен

4

InvalidEndpointError

Неверный endpoint

5

RateLimitError

Превышен лимит запросов

6

FieldError

Ошибка в конкретном поле (см. ошибка поле в ответе)

Все классы исключений наследуются от CloreAPIError и включают:

  • e.code — числовой код ошибки

  • e.response — полный словарь ответа API (когда доступен)


Ограничение частоты запросов

SDK включает встроенный ограничитель частоты, который автоматически соблюдает лимиты Clore.ai:

Endpoint
Лимит

Большинство endpoints

1 запрос/секунду

create_order

1 запрос/5 секунд

Когда API возвращает ошибку лимита (код 5), SDK применяет экспоненциальное затухание и повторяет попытки до max_retries раз (по умолчанию: 3). Вам не нужно добавлять time.sleep() между вызовами.

Как это работает

  1. Перед каждым запросом ограничитель частоты ждёт, пока не пройдет минимальный интервал.

  2. create_order вызовы накладывают дополнительную паузу в 5 секунд.

  3. При ошибках лимита SDK увеличивает паузы экспоненциально: 1с → 2с → 4с → ...

  4. После max_retries неудачных попыток, RateLimitError возникает исключение.

Настройка поведения повторных попыток


Конфигурация

Файл конфигурации

CLI сохраняет конфигурацию в ~/.clore/config.json:

Порядок разрешения

SDK определяет API-ключ в следующем порядке:

  1. api_key аргумент, переданный в конструктор

  2. CLORE_API_KEY переменная окружения

  3. api_key поле в ~/.clore/config.json

Environment variables

Переменная
Description

CLORE_API_KEY

API-ключ для аутентификации


Следующие шаги

Последнее обновление

Это было полезно?