API Reference
The NexusCompute REST API lets you integrate AI compute directly into your applications. All endpoints return JSON. The base URL for all requests is:
https://nexuscompute.app/apiNeed to compare capacity first? Read the GPU inference guide · Browse live marketplace listings
Paste your sk-nx-… key here once. It's stored in sessionStorage and cleared when you close the tab — never sent to our servers except as your request's Bearer token.
Getting Started
1. Create an account — Sign up via POST /auth/sign-up or through the web app at /auth/sign-up.
2. Get an API key — A signed-in operator creates a long-lived API key in the buyer dashboard or through POST /api-keys using the operator session. Store it securely — it is shown only once.
3. Authenticate requests — Pass your key in the Authorization header:
Authorization: Bearer sk-nx-YOUR_API_KEY
4. Browse listings — Call GET /listings to find GPU compute nodes. Connect to one with POST /connections, then dispatch inference jobs via POST /jobs.
Conventions
- All request bodies must be
Content-Type: application/json. - Successful creates return
201 Created. Successful deletes return204 No Content. - Errors return a JSON body with an
"error"string field and an appropriate 4xx status. - Token prices are expressed as USD per 1,000 tokens (e.g.
0.15= $0.15 / 1K tokens). - Monetary amounts in the billing API are in USD cents (integer).
- Fields marked * are required.
Authentication
Listings
Listings represent individual GPU compute nodes offered by Providers. Each listing includes pricing, hardware specs, and the AI model it serves.
Endpoints
Endpoints are named, reusable inference targets that point to a specific listing. Providers create endpoints; buyers call them.
Bounded retries and operator-controlled fallback
Treat 402 insufficient balance and 429 spend-threshold or rate-limit responses as non-retryable until an operator resolves the account condition. Retry 503 temporary capacity responses only a few times with capped exponential backoff and jitter. NexusCompute does not automatically fail over your workload; your application decides whether to use another provider, queue the task, or stop.
const url = "https://nexuscompute.app/api/v1/chat/completions";
const maxAttempts = 3;
class CapacityUnavailableError extends Error {}
class OutcomeUnknownError extends Error {}
export async function createChatCompletion(apiKey: string) {
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
let response: Response;
try {
response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "llama-3-70b",
messages: [{ role: "user", content: "Summarize this task." }],
max_tokens: 128,
}),
signal: AbortSignal.timeout(30_000),
});
} catch (error) {
// The POST may have reached the server. Retrying or falling back could
// duplicate a job and charge, so surface the ambiguous outcome instead.
throw new OutcomeUnknownError(
"Request timed out or disconnected; verify the job before resubmitting",
{ cause: error },
);
}
if (response.ok) return response.json();
// Funding and spend controls require operator action; do not retry.
if (response.status === 402 || response.status === 429) {
throw new Error(`Operator action required (HTTP ${response.status})`);
}
// Retry temporary capacity failures only, with a strict attempt limit.
if (response.status !== 503) {
throw new Error(`Chat completion failed (HTTP ${response.status})`);
}
if (attempt === maxAttempts) {
throw new CapacityUnavailableError("Capacity unavailable after 3 attempts");
}
const retryAfterHeader = response.headers.get("retry-after");
const retryAfter = retryAfterHeader === null ? NaN : Number(retryAfterHeader);
const backoffMs = Number.isFinite(retryAfter) && retryAfter >= 0
? Math.min(retryAfter * 1000, 10_000)
: Math.min(500 * 2 ** (attempt - 1) + Math.random() * 250, 10_000);
await new Promise((resolve) => setTimeout(resolve, backoffMs));
}
}
// The operator supplies this policy for definitive 503 responses: call another
// provider, enqueue the task, notify a human, or rethrow. NexusCompute does not
// choose it automatically. Ambiguous network failures are never caught here.
export async function runWithFallback(
apiKey: string,
operatorFallback: () => Promise<unknown>,
) {
try {
return await createChatCompletion(apiKey);
} catch (error) {
if (error instanceof CapacityUnavailableError) {
return operatorFallback();
}
throw error; // 402/429 still require operator action.
}
}import random
import math
import time
import requests
URL = "https://nexuscompute.app/api/v1/chat/completions"
MAX_ATTEMPTS = 3
class CapacityUnavailableError(RuntimeError):
pass
class OutcomeUnknownError(RuntimeError):
pass
def create_chat_completion(api_key: str):
for attempt in range(MAX_ATTEMPTS):
try:
response = requests.post(
URL,
headers={"Authorization": f"Bearer {api_key}"},
json={
"model": "llama-3-70b",
"messages": [
{"role": "user", "content": "Summarize this task."}
],
"max_tokens": 128,
},
timeout=30,
)
except requests.RequestException as error:
# The POST may have reached the server. Retrying or falling back
# could duplicate a job and charge, so surface the ambiguity.
raise OutcomeUnknownError(
"Request timed out or disconnected; "
"verify the job before resubmitting"
) from error
if response.ok:
return response.json()
# Funding and spend controls require operator action; do not retry.
if response.status_code in (402, 429):
raise RuntimeError(
f"Operator action required (HTTP {response.status_code})"
)
# Retry temporary capacity failures only, with a strict attempt limit.
if response.status_code != 503:
raise RuntimeError(
f"Chat completion failed (HTTP {response.status_code})"
)
if attempt == MAX_ATTEMPTS - 1:
raise CapacityUnavailableError(
"Capacity unavailable after 3 attempts"
)
retry_after = response.headers.get("Retry-After")
try:
delay = min(float(retry_after), 10.0)
if not math.isfinite(delay) or delay < 0:
raise ValueError
except (TypeError, ValueError):
delay = min(0.5 * (2 ** attempt) + random.uniform(0, 0.25), 10.0)
time.sleep(delay)
# The operator supplies this policy for definitive 503 responses: call another
# provider, enqueue the task, notify a human, or re-raise. NexusCompute does not
# choose it automatically. Ambiguous network failures are never caught here.
def run_with_fallback(api_key: str, operator_fallback):
try:
return create_chat_completion(api_key)
except CapacityUnavailableError:
return operator_fallback()
# 402/429 are not caught here; they still require operator action.Connections
A connection links a buyer to a listing and creates a scoped API key for that listing. The raw key is returned once at creation time — store it immediately.
Jobs
Jobs represent individual inference requests. Dispatching a job requires an API key and a positive credit balance. Billing is calculated once the job completes.
Billing
Buyers prepay a credit balance via Stripe Checkout. All amounts are in USD cents. The minimum balance required to dispatch a job is $1.00 (100 cents).
API Keys
API keys have the format sk-nx-… and authenticate requests via Authorization: Bearer sk-nx-YOUR_KEY. The raw key is returned once at creation — store it immediately. All subsequent calls return only the key prefix (first 8 characters after sk-nx-). Key and account management require the operator's signed-in browser session; an inference key cannot create, change, or revoke credentials.
NexusCompute API v1 · Questions? api@nexuscompute.com