Skip to main content

npm SDK API Reference

getTemplateUrl(options)

Retrieves the template associated with a document and returns a presigned URL that can be used directly to fetch the file. The presigned URL expires after 1 hour. Parameters:
ParameterTypeRequiredDescription
documentIdstringYesThe unique identifier of the document
accessTokenstringYesYour organization access token
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GetTemplateUrlResponse>
interface GetTemplateUrlResponse {
    templateUrl: string | null    // Presigned URL for the template file (expires in 1 hour)
    templateId: string | null     // Unique template identifier
    documentName: string | null   // Name of the document
    _raw: object                  // Full API response (for debugging)
}

getDocumentSources(options)

Lists all sources associated with a given section within a document. Used to populate the Sources panel when a user selects or highlights a section of the draft. Parameters:
ParameterTypeRequiredDescription
documentIdstringYesThe unique identifier of the document
sectionIdstringYesThe section ID to retrieve sources for
accessTokenstringYesYour organization access token
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GetDocumentSourcesResponse>
interface GetDocumentSourcesResponse {
    sources: Array<{
        documentSourceId: string | null    // Unique identifier of the source record
        documentSourceName: string | null  // Human-readable display name of the source
        referencedText: string | null      // Exact excerpt used to generate the section
        _raw: object                       // Full API response for this source
    }>
}

getDocumentSourceUrl(options)

Fetches the presigned URL for a given source reference, enabling preview of the original source material from within the Sources panel. Parameters:
ParameterTypeRequiredDescription
documentSourceIdstringYesSource ID obtained from getDocumentSources
accessTokenstringYesYour organization access token
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GetDocumentSourceUrlResponse>
interface GetDocumentSourceUrlResponse {
    documentSourceUrl: string | null    // Presigned URL to the original source document
    _raw: object                        // Full API response (for debugging)
}

getSectionFromText(options)

Given a user-defined text selection within the draft editor, identifies the enclosing section and returns its metadata. Use the returned sectionId with getDocumentSources to retrieve sources for that section. Parameters:
ParameterTypeRequiredDescription
documentIdstringYesThe document ID
highlightedTextstringYesThe raw text string of the user’s selection
accessTokenstringYesYour organization access token
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GetSectionFromTextResponse>
interface GetSectionFromTextResponse {
    sectionId: string | null    // ID of the section containing the highlighted text
    _raw: object                // Full API response (for debugging)
}

getDocumentSections(options)

Retrieves all sections for a given document, returning each section’s ID, title, and display order. Useful for building navigation, table of contents, or populating section selectors. Parameters:
ParameterTypeRequiredDescription
documentIdstringYesThe unique identifier of the document
accessTokenstringYesYour organization access token
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GetDocumentSectionsResponse>
interface GetDocumentSectionsResponse {
    sections: Array<{
        sectionId: string | null       // Unique identifier of the section
        sectionTitle: string | null    // Human-readable title of the section
        sectionOrder: number | null    // Display order within the document
        _raw: object                   // Full API response for this section
    }>
}

generateProxyUrl(options)

Fetches a file by streaming it through the backend’s proxy endpoint. Takes a presigned S3 URL and streams the file content back, returning it as a Blob. Useful for displaying source documents in the browser without exposing S3 URLs directly. Parameters:
ParameterTypeRequiredDescription
presignedUrlstringYesA presigned S3 URL to stream through the proxy
baseUrlstringYesThe Artos API base URL
apiClientApiClientNoPre-configured API client (advanced usage)
Returns: Promise<GenerateProxyUrlResponse>
interface GenerateProxyUrlResponse {
    blob: Blob          // The file content as a Blob
    contentType: string // The content type (e.g. 'application/pdf')
    proxyUrl: string    // The proxy URL used to fetch the file
}

TypeScript Support

The SDK includes full TypeScript definitions. Import types as needed:
import {
    getTemplateUrl,
    getDocumentSources,
    getDocumentSourceUrl,
    getSectionFromText,
    getDocumentSections,
    generateProxyUrl,
    createApiClient,
    ArtosAPIError
} from '@artosai/sdk'

import type {
    ApiClient,
    ApiClientConfig,
    ApiCallOptions,
    GetTemplateUrlOptions,
    GetTemplateUrlResponse,
    GetDocumentSourcesOptions,
    GetDocumentSourcesResponse,
    GetDocumentSourceUrlOptions,
    GetDocumentSourceUrlResponse,
    GetSectionFromTextOptions,
    GetSectionFromTextResponse,
    GetDocumentSectionsOptions,
    GetDocumentSectionsResponse,
    GenerateProxyUrlOptions,
    GenerateProxyUrlResponse,
    DocumentSource,
    DocumentSection
} from '@artosai/sdk'

Fully Typed Example

async function typedExample(): Promise<GetTemplateUrlResponse> {
    const options: GetTemplateUrlOptions = {
        documentId: 'doc-123',
        accessToken: process.env.ARTOS_ACCESS_TOKEN!,
        baseUrl: 'https://api.artosai.com'
    }

    const result: GetTemplateUrlResponse = await getTemplateUrl(options)
    return result
}