@motif-ai/sdk
v0.1.3
Published
Embed AI-powered wealth advisory into your platform — investor profiling, portfolio strategies, and market insights
Maintainers
Readme
@motif-ai/sdk
Embed AI-powered wealth advisory into your platform — investor profiling, portfolio strategies, and market insights.
Homepage | Documentation | Business | Blog
Install
npm install @motif-ai/sdkQuick Start
import { createClient } from '@motif-ai/sdk'
const client = createClient({
apiKey: process.env.MOTIF_API_KEY!,
})
// Create a user
const user = await client.users.create({
email: '[email protected]',
name: 'Jane Doe',
externalId: 'your_internal_id_123',
})
// List users
const { data: users } = await client.users.list({ limit: 10 })User-Scoped Operations
Operations like profiling and strategy recommendations are scoped to a specific user:
const userClient = client.forUser(user.id)
// Get profiling questions
const questions = await userClient.profile.getQuestions({ type: 'Basic' })
// Save an answer
await userClient.profile.saveAnswer({
questionId: questions[0].id,
answer: 'Growth',
})
// Compute investor profile from answers
const profile = await userClient.profile.computeInvestorProfile()
// Get recommended investment strategy
const strategy = await userClient.strategies.getRecommended()Configuration
const client = createClient({
apiKey: 'pk_live_...', // Required
baseURL: 'https://api.motifapp.ai/api', // Optional (default)
timeout: 30000, // Optional, ms (default: 30000)
headers: { 'x-custom': 'value' }, // Optional extra headers
})API Reference
createClient(config)
Returns a client with the following namespaces:
client.users
| Method | Description |
| ----------------------------- | -------------------------- |
| create(data) | Create a new user |
| list(params?) | List users with pagination |
| get(id) | Get user by ID |
| update(id, data) | Update user |
| delete(id) | Delete user |
| getByExternalId(externalId) | Get user by external ID |
client.forUser(userId)
Returns a user-scoped client with:
profile
| Method | Description |
| ------------------------------- | ------------------------------- |
| getQuestions(params) | Get profiling questions by tier |
| saveAnswer(data) | Save a profiling answer |
| getAnswers() | Get all answers |
| getInvestorProfile() | Get computed investor profile |
| computeInvestorProfile(data?) | Compute/refresh profile |
| getCompletion(params) | Check profiling completion |
strategies
| Method | Description |
| ------------------ | ---------------------------- |
| getRecommended() | Get recommended strategy |
| generate(data?) | Generate AI-powered strategy |
Error Handling
import { createClient, MotifSDKError } from '@motif-ai/sdk'
try {
const user = await client.users.get('invalid_id')
} catch (error) {
if (error instanceof MotifSDKError) {
console.error(error.message) // Human-readable message
console.error(error.statusCode) // HTTP status (e.g. 404)
console.error(error.response) // Raw response body
}
}Requirements
- Node.js >= 18
- TypeScript >= 5.0 (optional, for type checking)
License
Proprietary — see LICENSE. Use is permitted solely for integrating with the Motif API.
