Integration guide

Use ClipEmber from the Vercel AI SDK

Connect the Vercel AI SDK to the ClipEmber MCP server over HTTP with an API key, and run the preview-and-confirm step across two turns.

Uses the MCP server·TypeScript·updated

01Before you start

An API key, connected accounts, and the server address.

An API key
Create it in the app (API keys). New keys come with Pro and Agency, and during the 7-day Pro trial; a key you already have keeps working on any plan. The secret is shown once, so put it straight into your tool’s credential store. It goes in the X-API-Key header of every call.
Connected accounts
Connect TikTok, YouTube, Instagram and the rest in the app, through each network’s own sign-in. A key or an agent can’t sign in to a network for you. Each account has an id you pass as connectionId.
Server
https://clipember.com/api/mcp, streamable HTTP. Send the key as X-API-Key. The OAuth sign-in on the MCP page is for chat apps; code uses the key.
Packages
The AI SDK, its MCP client and a model provider. The MCP client has moved between packages across AI SDK versions; the code below uses createMCPClient from @ai-sdk/mcp — see the note under it for older versions.
npm install ai @ai-sdk/mcp @ai-sdk/openai

There is no ClipEmber package to install for this. Your code talks to the hosted MCP server at https://clipember.com/api/mcp — the same server Claude and ChatGPT connect to — over streamable HTTP, with your API key in a header.

02Connect

An MCP client over HTTP, its tools into generateText.

Server-side only: the API key must never reach a browser. Close the client when you're done.

agent.ts
import { createMCPClient } from "@ai-sdk/mcp";
import { openai } from "@ai-sdk/openai";
import { generateText, stepCountIs, type ModelMessage } from "ai";

const RULES = `You schedule social video posts with the ClipEmber tools.
- Before anything that schedules or posts now, call the tool once and show the user
  the preview it returns (networks, accounts, time, skipped networks, warnings).
- Only after the user says yes, call the same tool again with exactly the same
  arguments plus confirmed: true and the confirmationToken from the preview.
- Pass an idempotencyKey (for example a UUID) to tools that create things, and
  reuse it if you retry the same call.
- If a tool returns an error code, call clipember_explain_error with it and tell
  the user what to do. Never guess a TikTok audience: if the user didn't say who
  can see a TikTok post, leave it out and say the post waits for their choice.`;

const clipember = await createMCPClient({
  transport: {
    type: "http",
    url: "https://clipember.com/api/mcp",
    headers: { "X-API-Key": process.env.CLIPEMBER_API_KEY! },
  },
});

try {
  const tools = await clipember.tools(); // every clipember_* tool
  const run = (messages: ModelMessage[]) =>
    generateText({
      model: openai("gpt-4.1"),
      system: RULES,
      tools,
      stopWhen: stepCountIs(8),
      messages,
    });

  const messages: ModelMessage[] = [{
    role: "user",
    content: "Schedule media <mediaId> to my YouTube Shorts for Friday 6 pm, caption 'Launch day'.",
  }];
  const first = await run(messages);
  console.log(first.text); // the preview, waiting for a yes

  // The user's answer is the next turn; the model confirms with the token.
  messages.push(...first.response.messages, { role: "user", content: "Yes, schedule it." });
  const second = await run(messages);
  console.log(second.text);
} finally {
  await clipember.close();
}
Older AI SDK versions
Where @ai-sdk/mcp isn’t available, the same client is experimental_createMCPClient from ai, with a streamable HTTP transport from the MCP SDK that carries the header:
import { experimental_createMCPClient } from "ai";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const clipember = await experimental_createMCPClient({
  transport: new StreamableHTTPClientTransport(new URL("https://clipember.com/api/mcp"), {
    requestInit: { headers: { "X-API-Key": process.env.CLIPEMBER_API_KEY! } },
  }),
});
Fewer tools
clipember.tools() returns an object keyed by tool name; pass only the ones the task needs, e.g. clipember_create_post, clipember_upload_media_from_url, clipember_list_platform_connections and clipember_explain_error.

03Confirm before posting

The first call previews; only the second one posts.

This is enforced by the server, not by your prompt: a model can't schedule or publish in one call.

1. Preview
clipember_create_post with mode schedule or now (and other tools that schedule clips, a series, or move a draft into the schedule) creates nothing on the first call. It returns a preview with confirmation_required: true, a confirmationToken and expiresAt. The token is also in the tool’s text, so the model sees it.
2. The user says yes
Your app shows the preview and waits for a person. That reply is a new turn of the conversation.
3. Confirm
The model calls the same tool with exactly the same arguments plus confirmed: true and the token. The token lasts 10 minutes and fits only those arguments and your account; otherwise the call is refused with confirmation_invalid or confirmation_expired and nothing is created. In the AI SDK that’s the second generateText above, with first.response.messages kept in the history so the model still has the token.
Drafts
Mode draft skips the preview. If your agent runs with nobody to ask, let it save drafts and have a person schedule them in the app — or use the REST API, where your own code decides.

04Errors and retries

Branch on the code, not the message.

Tool errors
A failed tool call comes back as an error result: a message written for a person, and { error: { code, retryable } } in its structured content. retryable: true means the same call can work later (for example rate_limited); false means something has to change first.
Ask the server
clipember_explain_error takes a code and returns what it means, whether to retry and what to do — the same catalog as API error codes.
Safe retries
clipember_create_post, clipember_schedule_clips, clipember_create_clip_request and clipember_upload_media_from_url take an idempotencyKey. The same key and arguments within 10 minutes return the first result instead of a duplicate; the same key with other arguments gets idempotency_key_reused. A failed call doesn’t use up the key.
Limits
The agent runs as you: the same plan limits, monthly limits and per-minute rate limit as the app and the REST API.

05What to ask

A first prompt to try.

Read first
“Which accounts do I have connected, and what is scheduled for next week?” — uses clipember_list_platform_connections and clipember_list_scheduled_posts, changes nothing.
Then post
“Import https://example.com/launch.mp4 and schedule it to my YouTube Shorts for Friday 6 pm with the caption ‘Launch day’.” — clipember_upload_media_from_url, then clipember_create_post, which stops at the preview until the user confirms. The post can be created while the video is still importing; it waits for the file.

06Reference

Where the details live.

MCP server
Setup and every tool, grouped by job, with the TikTok rule and what stays in the app.
OpenAPI
The machine-readable description: /api/v1/openapi.json.
Error codes
Every code with its HTTP status, whether to retry and what to do.

Try it with a real account.

Every new account gets 7 days of Pro, API keys included. No card.