@picahq/ai

Install the Pica AI package to unlock powerful tools for the Vercel AI SDK

The Pica AI SDK is a powerful tool that allows you connect Pica with Vercel’s AI SDK for enhanced AI capabilities.

Configuration

The Pica SDK can be configured with the following options:

OptionTypeRequiredDefaultDescription
serverUrlStringNohttps://api.picaos.comURL for self-hosted Pica server.
connectorsString[]NoList of connector keys to filter by. Pass [”*”] to initialize all available connectors, or specific connector keys to filter. If empty, no connections will be initialized
identityStringNoNoneFilter connections by specific identifier.
identityType"user", "team", "project", "organization"NoNoneFilter connections by identity type.
authkitBooleanNofalseIf true, the SDK will use Authkit to connect to prompt the user to connect to a platform that they do not currently have access to
knowledgeAgentBooleanNofalseIf true, the SDK will never execute actions, but will use Pica’s knowledge to generate code. If true, use pica.intelligenceTool instead of pica.oneTool
knowledgeAgentConfigObjectNo{ includeEnvironmentVariables: true }Configuration for the Knowledge Agent. If includeEnvironmentVariables is true, the SDK will return a reminder to include environment variables in the output
const pica = new Pica(process.env.PICA_SECRET_KEY!, {
  serverUrl: "https://my-hosted-instance.com",
  connectors: [
    "test::gmail::default::0fc9f64d309349be8cccb63a02e16c2a",
    "test::notion::default::0fc9f64d309349be8cccb63a02e16c2a",
    "test::postgres::default::0fc9f64d309349be8cccb63a02e16c2a",
  ]
});

Installation

Install the Pica AI package:

npm install @picahq/ai

Examples

Install the required packages:

npm install ai openai @picahq/ai

Here’s an example of using Pica with OpenAI in a Next.js API route:

import { openai } from "@ai-sdk/openai";
import { convertToCoreMessages, streamText } from "ai";
import { Pica } from "@picahq/ai";

export async function POST(request: Request) {
  const { messages } = await request.json();

  const pica = new Pica(process.env.PICA_SECRET_KEY as string);

  const systemPrompt = await pica.generateSystemPrompt();

  const stream = streamText({
    model: openai("gpt-4o"),
    system: systemPrompt,
    tools: { ...pica.oneTool },
    messages: convertToCoreMessages(messages),
    maxSteps: 5,
  });

  return (await stream).toDataStreamResponse();
}

AuthKit

The authkit configuration option initiates Pica’s AuthKit. When enabled, the SDK will prompt the user to connect to a platform that they do not currently have access to.

const pica = new Pica(process.env.PICA_SECRET_KEY!, { 
  authkit: true // Simply pass true to enable AuthKit
});

Knowledge Agent

The knowledge agent is a configuration optional that initiates Pica’s knowledge agent. When enabled, the knowledge agent will be used to generate code instead of executing actions.

const pica = new Pica(process.env.PICA_SECRET_KEY!, { 
  knowledgeAgent: true
});

Demo

You can now use the chat interface directly in the Pica Dashboard.

@picahq/onetool-demo

View on GitHub

Want to learn more about Vercel AI SDK? Read the docs.