Models and API¶
The contree-client npm package is pure ESM with zero runtime
dependencies and full TypeScript declarations. There is no adapter
zoo: the platform fetch is the transport, and connection pooling,
TLS and gzip are the platform’s job.
npm install contree-client
Naming convention¶
Public JavaScript names use camelCase. Serialization keeps the exact API wire spelling:
Surface |
Style |
Example |
|---|---|---|
methods and functions |
camelCase |
|
model fields |
camelCase |
|
option-object keys |
camelCase |
|
Required arguments are positional, every optional knob rides in a trailing options object.
The client¶
import { ContreeClient, RetryPolicy } from "contree-client";
const client = new ContreeClient(token, {
baseUrl: "https://contree.example.com",
project: "my-project",
timeout: 300, // seconds, like the Python default
retry: new RetryPolicy(), // opt-in, identical semantics
identity: "my-app/1.2.3", // leads the User-Agent (Node only)
fetch: customFetch, // BYO transport: proxies, TLS, mocks
});
The token may be null, just like the project: the client then sends
no Authorization header, which is what the endpoints that need no
authentication expect.
fetch is the single customization point — wrap the platform fetch
to add an undici dispatcher (TLS options, proxies) in Node or a mock
in tests:
import { Agent } from "undici";
const dispatcher = new Agent({ connect: { ca: internalCa } });
const client = new ContreeClient(token, {
fetch: (url, options) => fetch(url, { ...options, dispatcher }),
});
ContreeClient.fromProfile() (Node only) reads the Contree profile
files ($CONTREE_HOME/{cli,auth}.ini, shared with the Python client),
including the active profile from [DEFAULT] and CONTREE_PROFILE. For config-less environments (CI, containers)
profiles.fromEnv() builds a profile from CONTREE_TOKEN /
NEBIUS_API_KEY, CONTREE_URL and CONTREE_PROJECT — a non-null
result means the environment fully described one.
Return shapes¶
The mapping from the Python client is one-to-one:
buffered calls resolve to typed models (
whoami(),getOperationStatus(),listImages(), …);checkFileExists()/checkImageFile()/checkImageArchive()resolve to booleans (HEAD, 404 meansfalse);inspectImageDownload()resolves to aUint8Array;inspectImageDownloadStream()andinspectImageArchive()areAsyncGenerator<Uint8Array>;iterOperationEvents()/followOperationEvents()yield typedOperationEvents — reconnection withLast-Event-Id, deadlines and in-bandsse_errorhandling match the Pythonfollow_operation_events;iterImages()/iterOperations()/iterFiles()paginate lazily with the samepageSize/limitknobs.
Helpers carry over unchanged: waitOperation(id, { timeout, followEvents }),
resolveImage(ref), ensureFile(content) (sha256 dedup; Blobs hash
chunk-by-chunk in Node).
Models¶
Generated classes expose fromWire() / toWire() instead of
from_dict() / to_dict(). The tri-state field semantics are the
Python ones: an unset optional field is undefined and omitted on the
wire, an explicit null is sent as JSON null. Timestamps become
Date where the spec says so.
StreamRepr,EventDataStream, andClosableStreamReprexpose codec helpers:asBytes(),asText(),StreamRepr.fromBytes(),StreamRepr.fromText(); module-leveldecodeChunk()/decodeStream()decode payloads that may be typed or raw.OperationResponse.metadatais discriminated bykind:OperationInstanceMetadataorImageImportMetadata.OperationEvent.datais discriminated byevent.type(EventDataStream,EventDataExit,EventDataCompletion, …); unknown payloads stay plain objects.OperationStatusconstants,TERMINAL_STATUSES/ACTIVE_STATUSESsets andisTerminalStatus()mirror the Python enum and frozen sets.
GrepMatch.asText() formats one grep row. GrepResult.asText() formats all rows
in response order, including context separators. DirectoryList.asText() returns
an ls -l-style table with UTC timestamps; asText(true) returns paths only.
Nonempty grep and directory output ends with a newline. Check truncated
separately on grep results.
These three models and all three stream models implement toString(), so
String(model) uses the default text format. Formatting preserves toWire()
and all fields. ClosableStreamRepr treats omitted encoding as ASCII; its
constructors leave close unset so the server default applies.
Errors¶
ContreeError
├── APIConnectionError
└── APIStatusError (status, error, traceback, retryAfter)
├── BadRequestError 400
├── AuthenticationError 401
├── PermissionDeniedError 403
├── NotFoundError 404
├── ConflictError 409
├── GoneError 410
├── UnprocessableEntityError 422
├── TooEarlyError 425
├── RateLimitError 429
└── ServerError >=500
ContreeClient.request() maps fetch and buffered body-read failures to
APIConnectionError. Its standard cause property keeps the original
error for diagnostics. timedOut is true for timeout failures. HTTP responses
with status 400 or higher map to APIStatusError or its matching subclass.
Local validation and response parsing use native JavaScript errors.
Stream status failures use RangeError. Other stream failures remain native.
Platform notes¶
Browsers forbid the
User-Agentheader — it is only attached in Node;client.userAgent()reports the composed value everywhere.fromProfile()andReadableStreamrequest bodies are Node-only.getNetworkPolicyTag()reads a JSON body from HTTP 302. Native browser fetch hides this body. Use Node.js or a custom fetch that exposes redirect responses.A truncated compressed download can end short because fetch hides the raw compressed bytes.
The complete generated surface — every method with its options and
every model with its fields — lives on the API reference
page, rendered from the same OpenAPI IR as the code; the package’s
.d.ts files carry the same information for your editor.