TypeScript SDK
Configure the TypeScript client and find the method for each workflow.
The package is @motif-ai/sdk. These guides follow the current 0.2.0 source contract. Confirm the package available to your organization and environment before upgrading an existing integration.
npm install @motif-ai/sdkCreate a client
import { createClient } from "@motif-ai/sdk";
const apiKey = process.env.MOTIF_API_KEY;
if (!apiKey) throw new Error("MOTIF_API_KEY is required");
const motif = createClient({
apiKey,
baseURL: "https://staging.backend.motifapp.ai/api",
timeout: 30_000,
});
const portfolios = await motif.portfolios.list({ limit: 25 });
console.log(portfolios);apiKey is required. baseURL defaults to https://backend.motifapp.ai/api; timeout defaults to 30,000 milliseconds for ordinary HTTP requests. headers accepts additional request headers. Client instances retain their own configuration. Prefer createClient for services serving multiple organizations; the legacy configure export changes shared module configuration.
Method directory
Arguments and response models correspond to the REST contracts, except where the helpers below shape the transport for you.
assets
list(params?), get(assetId), create(input), update(assetId, input), putPrice(assetId, input), prices(assetId, params?), createDocument(assetId, input), finalizeDocument(assetId, documentId), document(assetId, documentId)
portfolios
list(params?), putSnapshot(externalId, input), get(externalId), archive(portfolioId)
users
create(input), get(id), getByExternalId(externalId), list(params?), update(id, input), delete(id)
questionnaires
create(input)
feeds
mappings(), saveMapping(input), previewMapping(input), connection(), saveConnection(input), setConnectionEnabled(enabled), issueConnectorCredentials(), receipt(eventId, {source}), subscription(), configureSubscription(input), fxRate(params)
webhooks
list(), create(input), update(id, input), delete(id), rotateSecret(id), test(id), deliveries(id, params?), replay(id, deliveryId)
clarity
assetById(assetId, params?), portfolioById(portfolioId, params?), marketUpdate(input?), assetUpdate(input), portfolioCard(input), holdingAnalysis(input), createEmbed(input), sourceDocuments(input), chat(input, signal?)
partnerPortfolios
create(input), get(id), update(id, patch), delete(id), recordTrades(id, {currentHoldings, trades})
putSnapshot takes the external account ID separately from the body. archive takes the native portfolio ID returned by Motif. partnerPortfolios stores research context and uses a different ID namespace.
portfolioCard and holdingAnalysis take userId in their input and send it as x-user-id. assetById and portfolioById use exact resource IDs instead. sourceDocuments returns an array; the embed HTTP route returns an object containing documents.
User-scoped methods
Call motif.forUser(motifUserId) with an authorized Motif user ID, not your external customer reference. It creates a scoped helper without changing the parent client's configuration.
profile
getQuestions(params), getAnswers(), saveAnswer(input), getCompletion(params), getInvestorProfile(), computeInvestorProfile(input?)
strategies
getRecommended(), generate(input?)
See Profiling for a complete sequence.
Models and failures
The package exports generated request/response models and the native portfolio aliases PortfolioSnapshotInput, PortfolioSnapshotReceipt, and PortfolioSnapshotView. Use these to type application boundaries; validate untrusted input before submitting it.
MotifSDKError exposes statusCode and the response body when available. A missing status can mean no response was received, not that a mutation failed to commit. Reconcile or use the operation's revision semantics before retrying.
Chat is an async generator over SSE. It is not governed by the ordinary Axios request lifecycle. Use an AbortSignal to cancel, and consume the current wire events; older exported event declarations do not fully describe that wire stream.
The package also exports verifyWebhookSignature and isAssessmentPublishedEvent. Use the webhook example to verify raw bodies before processing notifications.
Last updated