---
name: masheev-api
description: >-
  Use when calling the Masheev API for contacts, conversations, messages, inboxes, AI agents, knowledge base, or any server-to-server integration. Covers authentication with API keys, the @masheev/client tRPC client, REST endpoints, pagination, rate limiting, and common CRUD operations. Use this skill whenever someone asks to "call the Masheev API", "create contacts", "list conversations", "send messages", "manage inboxes", or integrate Masheev into their backend. Also use when setting up @masheev/client in Node.js, React, Next.js, or React Native.
license: Apache-2.0
metadata:
  author: masheev
  version: "0.1.0"
title: masheev-api
canonical_url: https://skilld.dev/gh/masheev/skills/masheev-api
last_updated: 2026-11-12T05:30:47.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/contacts.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/contacts.md), [references/conversations.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/conversations.md), [references/inboxes.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/inboxes.md), [references/messages.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/messages.md).
>
> If the user asked to install this Skill, run `npx skilld install masheev/skills/masheev-api`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/masheev-api`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/masheev/skills/masheev-api) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/masheev-api`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/masheev-api --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/masheev-api --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Masheev API

Server-side API for managing contacts, conversations, messages, inboxes, AI agents, and more. The API uses tRPC — install `@masheev/client` for type-safe access.

## Quick Start

```bash
npm install @masheev/client
```

### Server-Side (Node.js / API Routes)

```typescript
import { apiClient, authClient } from "@masheev/client/server";

// List conversations
const conversations = await apiClient.conversations.list.query({
  status: "open",
  limit: 20,
});

// Send a message
await apiClient.messages.create.mutate({
  conversationId: "conv_...",
  role: "agent",
  content: "Thanks for reaching out! Let me help with that.",
});
```

### React (Client-Side)

```typescript
import { apiClient, authClient } from "@masheev/client/react";

function ConversationList() {
  const { data } = apiClient.conversations.list.useQuery({ status: "open" });
  return data?.map((c) => <div key={c.id}>{c.subject}</div>);
}
```

### Next.js (TanStack Start)

```typescript
import { apiClient } from "@masheev/client/tanstack";
```

### React Native

```typescript
import { apiClient } from "@masheev/client/native";
```

## Authentication

The API uses session-based authentication via Better Auth. For server-to-server integrations, use API keys:

```typescript
// API key in Authorization header
fetch("https://api.masheev.com/api/...", {
  headers: {
    Authorization: "Bearer YOUR_API_KEY",
  },
});
```

Generate API keys in the Masheev dashboard: **Settings > Developers > API Keys**

## API Reference

Each domain is a separate reference file with full endpoint details, input schemas, and response types.

| Domain | Endpoints | Reference |
|--------|-----------|-----------|
| Contacts | list, get, create, update, merge, GDPR delete | [references/contacts.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/contacts.md) |
| Conversations | list, get, update, batchUpdate, archive | [references/conversations.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/conversations.md) |
| Messages | list, get, create | [references/messages.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/messages.md) |
| Inboxes | list, get, create, update, delete | [references/inboxes.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/inboxes.md) |
| AI Agents | list, get, create, update, delete | [references/ai-agents.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/ai-agents.md) |
| Webhooks | list, create, update, delete, test, regenerateSecret | See masheev-webhooks skill |
| Knowledge | list, create, sync, delete, search | [references/knowledge.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/knowledge.md) |
| Automations | list, get, create, update, delete, activate | [references/automations.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/automations.md) |
| Billing | plans, balance, budget, topup, invoices | [references/billing.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/billing.md) |
| Organization | list, get, update, inviteUser, removeUser | [references/org.md](https://skilld.dev/api/skills-raw/masheev/skills/masheev-api/references/org.md) |

## Data Model

### Key Entities

| Entity | ID Prefix | Description |
|--------|-----------|-------------|
| Organization | `org_` | Your account / workspace |
| Inbox | `inb_` | A channel endpoint (chat, WhatsApp, email, etc.) |
| Contact | `con_` | A customer or visitor |
| Conversation | `conv_` | A thread between a contact and your team/AI |
| Message | `msg_` | A single message within a conversation |
| AI Agent | `aia_` | An AI agent configuration |
| Webhook | `wh_` | A webhook subscription |

### Common Enums

```typescript
type Channel = "voice" | "sms" | "whatsapp" | "chat" | "email" | "instagram" | "google_reviews";
type ConversationStatus = "open" | "pending" | "snoozed" | "resolved";
type Priority = "low" | "medium" | "high" | "urgent";
type MessageRole = "contact" | "ai" | "agent" | "system";
type MessageStatus = "pending" | "sent" | "delivered" | "read" | "failed";
type AssigneeType = "ai" | "agent" | "unassigned";
```

## Common Patterns

### Pagination

```typescript
// Cursor-based pagination
let cursor: string | undefined;
const allContacts = [];

do {
  const page = await apiClient.contacts.list.query({
    limit: 100,
    cursor,
  });
  allContacts.push(...page.items);
  cursor = page.nextCursor;
} while (cursor);
```

### Rate Limiting

The API enforces rate limits per IP and per user. When rate-limited, you receive a 429 response.

```typescript
async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      return await fn();
    } catch (error: any) {
      if (error.data?.httpStatus === 429 && attempt < maxRetries - 1) {
        const delay = Math.pow(2, attempt) * 1000; // Exponential backoff
        await new Promise((r) => setTimeout(r, delay));
        continue;
      }
      throw error;
    }
  }
  throw new Error("Max retries exceeded");
}
```

### Error Handling

tRPC errors include structured data:

```typescript
try {
  await apiClient.contacts.create.mutate({ ... });
} catch (error) {
  if (error instanceof TRPCClientError) {
    console.error(error.message);       // Human-readable message
    console.error(error.data?.code);    // "NOT_FOUND", "FORBIDDEN", etc.
    console.error(error.data?.zodError); // Validation errors (if input was invalid)
  }
}
```
