Skip to main content
This page provides ready-to-use API client implementations that you can copy into your projects. These clients are used throughout the cookbook examples.

TypeScript / Node.js Client

import axios, { AxiosInstance } from "axios";
import * as fs from "fs";

interface Workspace {
    id: number;
    name: string;
    icon: string;
}

interface Template {
    id: string;
    name: string;
    description?: string;
    schema_json: object;
}

interface Session {
    id: string;
    name: string;
    created_at: string;
}

interface ExtractionResult {
    id: string;
    status: "created" | "processing" | "completed" | "failed";
    data: Record<string, any>;
    reasoning?: Record<string, any>;
}

export class RaydocsClient {
    private client: AxiosInstance;

    constructor(apiKey: string, baseUrl: string = "https://api.raydocs.com") {
        this.client = axios.create({
            baseURL: baseUrl,
            headers: {
                Authorization: `Bearer ${apiKey}`,
                "Content-Type": "application/json",
                Accept: "application/json",
            },
        });
    }

    // ─────────────────────────────────────────────────────────────
    // Workspaces
    // ─────────────────────────────────────────────────────────────

    async listWorkspaces(): Promise<Workspace[]> {
        const { data } = await this.client.get("/workspaces");
        return data.data;
    }

    async createWorkspace(
        name: string,
        icon: string = "📊"
    ): Promise<Workspace> {
        const { data } = await this.client.post("/workspaces/create", {
            name,
            icon,
        });
        return data;
    }

    // ─────────────────────────────────────────────────────────────
    // Templates
    // ─────────────────────────────────────────────────────────────

    async listTemplates(workspaceId: number): Promise<Template[]> {
        const { data } = await this.client.get(
            `/workspaces/${workspaceId}/extractions/templates`
        );
        return data.data;
    }

    async createTemplate(
        workspaceId: number,
        name: string,
        schema: object,
        description?: string
    ): Promise<Template> {
        const { data } = await this.client.post("/extractions/templates", {
            workspace_id: workspaceId,
            name,
            schema_json: schema,
            description,
        });
        return data;
    }

    async getTemplate(templateId: string): Promise<Template> {
        const { data } = await this.client.get(
            `/extractions/templates/${templateId}`
        );
        return data;
    }

    // ─────────────────────────────────────────────────────────────
    // File Upload
    // ─────────────────────────────────────────────────────────────

    async uploadFile(filePath: string): Promise<string> {
        // Get signed upload URL (content_type defaults to 'application/octet-stream')
        const { data: uploadData } = await this.client.post(
            "/vapor/signed-storage-url",
            {
                visibility: "private",
            }
        );

        // Upload directly to S3
        const fileBuffer = fs.readFileSync(filePath);
        await axios.put(uploadData.url, fileBuffer, {
            headers: uploadData.headers,
        });

        return uploadData.key;
    }

    // ─────────────────────────────────────────────────────────────
    // Batch Operations
    // ─────────────────────────────────────────────────────────────

    async batchCreateSessions(
        templateId: string,
        fileKeys: string[],
        autoExtract: boolean = true
    ): Promise<Session[]> {
        const { data } = await this.client.post(
            `/extractions/templates/${templateId}/sessions/batch`,
            {
                files: fileKeys,
                settings: { auto_extract: autoExtract },
            }
        );
        return data;
    }

    // ─────────────────────────────────────────────────────────────
    // Sessions & Results
    // ─────────────────────────────────────────────────────────────

    async getSession(sessionId: string): Promise<any> {
        const { data } = await this.client.get(
            `/extractions/sessions/${sessionId}`
        );
        return data;
    }

    async getResults(sessionId: string): Promise<ExtractionResult[]> {
        const { data } = await this.client.get(
            `/extractions/sessions/${sessionId}/results`
        );
        return data.data;
    }

    async getResult(resultId: string): Promise<ExtractionResult> {
        const { data } = await this.client.get(
            `/extractions/results/${resultId}`
        );
        return data;
    }
}

Installation

npm install axios
Save the client as raydocs-client.ts:
import { RaydocsClient } from "./raydocs-client";

const client = new RaydocsClient("your_api_token");

Next Steps