Repository navigation
API Reference
2DAITeam edited this page Jul 28, 2026
·
19 revisions
interface ClientOptions {
apiKey: string; // required — '2dai_sk_…'
baseUrl?: string; // default 'https://dapp.2dai.io:444'
fetch?: typeof fetch;
timeoutMs?: number; // default 60000
maxRetries?: number; // default 2
userAgent?: string;
}client.baseUrl: stringclient.me(signal?): Promise<Account>-
client.download(ref, opts?)— shortcut forclient.cdn.download
generate.image(params: ImageParams, opts?: SubmitOptions): Promise<GenerationResult> // { wait:true } default
generate.image(params: ImageParams, opts: { wait:false } & SubmitOptions): Promise<QueueTicket>
generate.imageWithRefs(params: RefParams, opts?): Promise<GenerationResult | QueueTicket>
generate.video(params: VideoParams, opts?): Promise<GenerationResult | QueueTicket>SubmitOptions: { wait? (default true), intervalMs? (default 2000), timeoutMs? (default 300000), signal? } — same defaults for WaitOptions.
interface RefParams {
tool: 'face-ref' | 'character-ref' | 'style-transfer';
refCreationIds: string[]; // ≤6 identity refs (face/character) · ≤3 style sources
prompt?; quality?; aspectRatio?; width?; height?; allowNSFW?;
extractionDirective?; // style-transfer only, default 'style'
clientToken?;
}
interface VideoParams {
prompt: string; inputCreationId: string;
duration?; // seconds, tier-gated
quality?; style?; frameInterpolation?; allowNSFW?; clientToken?;
}queue.get(queueId: string, signal?): Promise<QueueState>
queue.waitFor(queueId: string, opts?: WaitOptions): Promise<QueueState> // resolves on any terminal statuscreations.list(opts?: ListOptions): Promise<CreationPage>
creations.get(ref: CreationRef, signal?): Promise<Creation>
creations.move(ref, target: string | null, signal?): Promise<{ creationId, folderId }> // 'root'|null = detach
creations.trash(ref, signal?): Promise<{ creationId, trashed }>
creations.restore(ref, signal?): Promise<{ creationId, trashed }>
creations.delete(ref, signal?): Promise<{ creationId, deleted }> // must be trashed first
creations.publish(ref, signal?): Promise<{ creationId, isPublicShared }>
creations.unpublish(ref, signal?): Promise<{ creationId, isPublicShared }>ListOptions: { limit?, beforeDate?, folderId?, trashed?, signal? }
(folderId: 'root' = ungrouped root).
folders.list(signal?): Promise<Folder[]>
folders.create(input: { title, description? }, signal?): Promise<Folder>
folders.update(folderId, patch: { title?, description? }, signal?): Promise<Folder>
folders.delete(folderId, opts?: { trashContents?, signal? }): Promise<{ folderId, deleted }>uploads.image(input: UploadInput): Promise<Creation>
// UploadInput: { path? } | { data: Uint8Array|ArrayBuffer|Blob } | { base64 }, + filename?, contentType?, signal?cdn.url(ref: CdnRef): string
cdn.fetch(ref: CdnRef, signal?): Promise<CdnAsset> // { bytes, contentType, ext }
cdn.download(ref, opts?: { savePath?, signal? }): Promise<string | CdnAsset>
cdn.toBlob(ref, signal?): Promise<Blob>
cdn.toDataUrl(ref, signal?): Promise<string>interface Account { userId; username?; creditUsd; tier; key: KeyContext }
interface KeyContext { keyId; label; scopes: Scope[]; spendLimitUsd: number|null; spentUsd }
type Scope = 'read' | 'generate' | 'manage' | 'publish'
interface QueueTicket { queueId; status: QueueStatus; costUsd? } // costUsd present when a charge applied
interface ApiErrorBody { error?; message?; [key: string]: unknown } // raw parsed error payload (err.details)
interface GenerationResult extends Creation { queueId; costUsd? }
interface Creation {
creationId; prompt?; toolKind?; style?; quality?; aiModel?;
cdnId?; downloadUrl?; width?; height?; isUploaded?; source?; nsfwRate?; creationDate?; raw?
// source: 'web' | 'sdk' | 'mcp' | 'api' — creation origin (SDK ≥ 2.0.1)
}
interface QueueState { queueId; status; costUsd?; creationId?; cdnId?; downloadUrl?; error?; createdAt?; completedAt? }
type QueueStatus = 'pending'|'pendingCharge'|'processing'|'inProgress'|'completed'|'failed'|'cancelled'|'dismissed'|'timeout'
interface Folder { folderId; title?; description?; icon?; kind?; isPublicShared?; isShared?; posterCreationId?; createdAt?; updatedAt?; raw? }
interface CreationPage { creations: Creation[]; nextBeforeDate? }
type CdnRef = string | { cdnId?; outputCdnId?; downloadUrl? }
type CreationRef = string | { creationId? }
type AspectRatio = '1:1'|'16:9'|'9:16'|'4:3'|'3:4'|'3:2'|'2:3'See Error Handling for the full error class table.