Creates a new Mosaia SDK instance
Initializes the SDK with the provided configuration and sets up the internal configuration manager. The configuration is used for all subsequent API requests.
Configuration object for the SDK
Configuration interface for the Mosaia SDK
This interface defines all configuration options available when initializing the Mosaia SDK client. It includes authentication settings, API endpoints, and optional context parameters.
OptionalapiKey?: stringAPI key for authentication (optional if using OAuth)
Optionalversion?: stringAPI version to use (defaults to '1')
OptionalapiURL?: stringBase URL for API requests (defaults to https://api.mosaia.ai)
OptionalclientId?: stringClient ID for client credentials flows (Optional)
OptionalclientSecret?: stringClient secret for client credentials flow (optional)
Optionalverbose?: booleanEnable verbose HTTP request/response logging (defaults to false)
Optionalsession?: SessionCredentialsSession credentials for OAuth and token-based authentication (optional)
const mosaia = new SDK.MosaiaClient({
apiKey: 'your-api-key',
apiURL: 'https://api.mosaia.ai',
appURL: 'https://mosaia.ai',
clientId: 'your-client-id'
});
// Minimal configuration with API key
const mosaia = new SDK.MosaiaClient({
apiKey: 'your-api-key'
});
// Full configuration with OAuth support
const mosaia = new SDK.MosaiaClient({
apiKey: 'your-api-key',
apiURL: 'https://api.mosaia.ai',
version: '1',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
user: 'user-id',
org: 'org-id'
});
Get the current configuration
Returns the current configuration object used by this client instance.
The current configuration object
Set the configuration
Updates the configuration for this client instance. This will affect all subsequent API requests made through this client.
The new configuration object
Set the API key for authentication
Updates the API key used for authenticating requests to the Mosaia API. This can be used to change authentication credentials at runtime.
The new API key for authentication
Set the API version
Updates the API version used for requests. This affects the version header sent with API requests.
The new API version (e.g., '1', '2')
Set the API base URL
Updates the base URL used for API requests. This is useful for switching between different environments (development, staging, production).
The new API base URL
Set the OAuth client ID
Updates the OAuth client ID used for authentication flows. This is required for OAuth-based authentication.
The new OAuth client ID
Set the OAuth client secret
Updates the OAuth client secret used for client credentials flow. This is used for server-to-server authentication.
The new OAuth client secret
const mosaia = new SDK.MosaiaClient(config);
// Update OAuth client secret
mosaia.clientSecret = 'new-client-secret-456';
// Use client credentials flow with updated secret
const auth = new Auth(mosaia.config);
const authResponse = await auth.signInWithClient(
mosaia.config.clientId!,
mosaia.config.clientSecret!
);
Access to Authentication API
Handle authentication flows, including sign in, sign out, token refresh, and session management.
Authentication API client
// Sign in with password
const auth = await mosaia.auth.signInWithPassword('user@example.com', 'password', 'client-id');
// Sign in with client credentials
const auth = await mosaia.auth.signInWithClient('client-id', 'client-secret');
// Refresh token
const newAuth = await mosaia.auth.refreshToken('refresh-token');
// Sign out
await mosaia.auth.signOut();
Access to Agents API
Manage AI agents, including CRUD operations, chat completions, and agent-specific functionality.
Agents API client
Access to Applications API
Manage applications, including CRUD operations and app-specific functionality.
Applications API client
Access to Tools API
Manage tools and integrations, including CRUD operations and tool-specific functionality.
Tools API client
Access to Users API
Manage users, including CRUD operations, authentication, and user-specific functionality.
Users API client
Access to Organizations API
Manage organizations, including CRUD operations and organization-specific functionality.
Organizations API client
Access to Models API
Manage AI models, including CRUD operations and model-specific functionality.
Models API client
Access to App Connectors API
Manage app connectors, which are specialized integrations that connect applications with AI agents or agent groups through webhook-style interactions.
App Connectors API client
// Get all app connectors
const connectors = await mosaia.appConnectors.get();
// Get a specific app connector
const connector = await mosaia.appConnectors.get({}, 'connector-id');
// Create a new app connector
const newConnector = await mosaia.appConnectors.create({
app: 'app-id',
response_url: 'https://myapp.com/webhook',
agent: 'agent-id'
});
Access to App Webhooks API
Manage app webhooks, which enable external systems to receive notifications about application events through webhook-style interactions.
App Webhooks API client
// Get all app webhooks
const webhooks = await mosaia.appWebhooks.get();
// Get a specific app webhook
const webhook = await mosaia.appWebhooks.get({}, 'webhook-id');
// Create a new app webhook
const newWebhook = await mosaia.appWebhooks.create({
app: 'app-id',
url: 'https://myapp.com/webhook',
events: ['REQUEST'],
secret: 'webhook-secret-key'
});
Access to Search API
Perform universal search across multiple resource types (agents, apps, tools, models) with a single query.
Search API client
// Search across all resource types
const results = await mosaia.search.query({
q: 'customer support',
limit: 10
});
// Access results by type
console.log('Agents:', results.data.agents);
console.log('Apps:', results.data.apps);
console.log('Tools:', results.data.tools);
console.log('Models:', results.data.models);
Access to Drives API
Manage drives, which are containers for organizing and managing files and documents, scoped to users or organizations.
Drives API client
// Get all drives
const drives = await mosaia.drives.get();
// Get a specific drive
const drive = await mosaia.drives.get({}, 'drive-id');
// Create a new drive
const newDrive = await mosaia.drives.create({
name: 'My Documents',
description: 'Personal document storage'
});
// Access drive items
const items = await drive.items.get();
Access to Logs API
Manage agent logs, which track conversations and interactions with agents.
Logs API client
Access to Scopes API
Get permission scopes available in the platform.
Scopes API client
Access to Notifications API
Send email notifications through the platform.
Notifications API client
Access to Snapshots API
Manage snapshots, which are point-in-time captures of data.
Snapshots API client
Access to Vector Indexes API
Manage vector indexes for semantic search and similarity matching.
Vector Indexes API client
Get the current user session
Retrieves information about the currently authenticated user, including user details, organization information, and permissions.
Session object containing user and organization information
Creates a new OAuth instance for handling OAuth2 Authorization Code flow with PKCE
This method creates an OAuth client that supports the PKCE (Proof Key for Code Exchange) flow for secure authentication, even for public clients.
OAuth configuration object
OAuth configuration interface
Configuration object for OAuth2 Authorization Code flow with PKCE. Used when initializing OAuth instances for secure authentication. This interface defines all the parameters needed to configure OAuth authentication flows.
OptionalredirectUri?: stringRedirect URI for the OAuth flow (optional)
OptionalappURL?: stringApp URL for authorization endpoints (optional defaults to https://mosaia.ai)
Optionalscopes?: string[]Array of scopes to request (optional)
OptionalclientId?: stringOAuth client ID (required only if not using default)
OptionalapiURL?: stringAPI URL for API endpoints (required only if not using default)
OptionalapiVersion?: stringAPI version (required only if not using default)
Optionalstate?: stringState parameter for CSRF protection (optional)
OAuth instance for handling the authentication flow
// Initialize OAuth
const oauth = mosaia.oauth({
redirectUri: 'https://your-app.com/callback',
scopes: ['read', 'write']
});
// Get authorization URL and code verifier
const { url, codeVerifier } = oauth.getAuthorizationUrlAndCodeVerifier();
// Redirect user to the authorization URL
// After user authorizes, you'll receive a code in your callback
// Exchange code for new authenticated config (requires the code verifier)
const newConfig = await oauth.authenticateWithCodeAndVerifier(code, codeVerifier);
// create new instance with authenticated config
const newMosaiaInstance = new SDK.MosaiaClient(newConfig);
Main Mosaia SDK client class
Provides access to all Mosaia API endpoints through a unified interface. Supports authentication, user management, organization management, AI agents, tools, applications, and more.
The MosaiaClient is the primary entry point for all SDK operations. It manages configuration, authentication, and provides access to all API collections.
Example
Example