Quickstart
Prepare an API Key. The default is https://api.deepraxis.com; override it with PRAXIS_API_BASE. Save the code below as quickstart.mjs and run it with Node.js. It creates a library, uploads a private image, searches by tag, verifies anonymous 404 and authorized 200, then explicitly publishes another image and verifies anonymous 200.
# Node.js 18+ or Bun; the example uses fetch and a data URI.# Set PRAXIS_API_KEY in your environment.node quickstart.mjsimport { writeFile } from "node:fs/promises";
const base = process.env.PRAXIS_API_BASE ?? "https://api.deepraxis.com";const key = process.env.PRAXIS_API_KEY;if (!key) throw new Error("Set PRAXIS_API_KEY");async function media(path, method = "GET", body) { const response = await fetch(base + "/media/v1" + path, { method, headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" }, ...(body === undefined ? {} : { body: JSON.stringify(body) }), }); if (!response.ok) throw new Error(`Media HTTP ${response.status}: ${await response.text()}`); return response.json();}// A library isolates its assets, folders and searches.const library = await media("/libraries", "POST", { name: "Agent media", understanding: { embedding: true } });const asset = await media(`/libraries/${library.id}/assets`, "POST", { file: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAABWklEQVR4nO3OQQ0AMBAEofVv+iqDxzRBALvtg/wgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwg7gEgaMOyrMtNTwAAAABJRU5ErkJggg==", public_id: "quickstart/pixel", tags: ["docs"],});if (asset.type !== "authenticated") throw new Error("New uploads must be private");if (asset.material_type !== "image") throw new Error(`Expected material_type image, got ${asset.material_type}`);// One type axis: material_type. Audio is audio, and audio_role tells speech, music and sound effects apart.const images = await media(`/libraries/${library.id}/search/expression`, "POST", { expression: "material_type:image AND tags=docs",});if (images.resources.length !== 1) throw new Error("Expression search did not find the upload");// Store this reference, never a signed URL or token.const reference = { library_id: library.id, asset_id: asset.asset_id, version: asset.version };const { token } = await media(`/libraries/${library.id}/delivery_tokens`, "POST", { acl: `/${library.id}/image/authenticated/*`, expires_in: 900,});const publicId = asset.public_id.split("/").map(encodeURIComponent).join("/");const original = new URL(`/${library.id}/image/authenticated/v${asset.version}/${publicId}.${asset.format}`, asset.secure_url);const thumbnail = new URL(original);thumbnail.pathname = thumbnail.pathname.replace("/authenticated/", "/authenticated/w_160,c_fit/");async function expectStatus(url, expected) { const response = await fetch(url); if (response.status !== expected) throw new Error(`Expected ${expected}, got ${response.status}`); const body = Buffer.from(await response.arrayBuffer()); if (expected === 200 && body.length === 0) throw new Error("Delivery returned an empty body");}await expectStatus(original, 404);await expectStatus(thumbnail, 404);original.searchParams.set("__cld_token__", token);thumbnail.searchParams.set("__cld_token__", token);await expectStatus(original, 200);await expectStatus(thumbnail, 200);// Catalogue images and avatars require an explicit public upload.const published = await media(`/libraries/${library.id}/assets`, "POST", { file: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAABWklEQVR4nO3OQQ0AMBAEofVv+iqDxzRBALvtg/wgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwgzg/i/CDOD+L8IM4P4vwg7gEgaMOyrMtNTwAAAABJRU5ErkJggg==", public_id: "quickstart/public-pixel", type: "upload",});if (published.type !== "upload") throw new Error("Expected public delivery");await expectStatus(published.secure_url, 200);const current = await media(`/libraries/${library.id}/assets/${asset.asset_id}`);const matches = current.semantic === "ready" ? await media(`/libraries/${library.id}/search/semantic`, "POST", { query: "a small image", top_k: 5 }) : null;// Print the reference and the counts, never a token or a token-bearing link: those are per-read and not stored.console.log({ reference, public_asset_id: published.asset_id, found_count: images.resources.length, semantic: current.semantic, matches_count: matches?.hits?.length ?? 0 });Delivery tokens default to 900 seconds and frame links last 300 seconds. Resolve a fresh link from the asset reference after expiry. Persist library_id, asset_id, version and the representation, never tokens or token-bearing URLs; keep them out of logs and share them only with intended readers.
Understanding completes asynchronously. Upload responses carry no processing state; GET the asset to read processing and semantic. Rough scale: about half a minute for an image, about 50 seconds for a 3-second video, and immediately for raw files (no understanding). Initial results may be empty. When matches is null, read the asset again later and search once semantic is ready. Understanding and semantic search are available. Uploading, expression search, and original access do not need to wait for understanding.
The example keeps the library. When finished, set LIBRARY_ID to reference.library_id in the output and delete it:
curl -X DELETE "${PRAXIS_API_BASE:-https://api.deepraxis.com}/media/v1/libraries/${LIBRARY_ID}" \ -H "Authorization: Bearer $PRAXIS_API_KEY"In the Console
No code needed: open Console → Media (/media), click 「新建素材库」 to create a library, open it and click 「上传素材」 to upload files.