Pica AI SDK is a TypeScript library that allows you to integrate with Pica's AI platform.
npm install @picahq/ai
- Create a new Pica account at Pica
- Create a Pica API key at Pica
- Set the API key as an environment variable:
PICA_SECRET_KEY=<your-api-key>
- Set the OpenAI API key as an environment variable:
OPENAI_API_KEY=<your-openai-api-key>
Here's a basic example of how to use the SDK:
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-4"),
system: systemPrompt,
tools: { ...pica.oneTool },
messages: convertToCoreMessages(messages),
maxSteps: 5,
});
return (await stream).toDataStreamResponse();
}