@cortiqa/sdk
v0.1.1
Published
Official TypeScript & JavaScript client library for Cortiqa AI & Falin Foundation Models
Maintainers
Readme
Cortiqa AI TypeScript & JavaScript SDK
Official TypeScript and JavaScript client library for Cortiqa AI and Falin Foundation Models. Built for modern full-stack web applications, edge runtimes, Next.js, and autonomous AI agents.
⚡ Installation
npm install @cortiqa/sdkOr using pnpm / yarn / bun:
pnpm add @cortiqa/sdk
# or
yarn add @cortiqa/sdk
# or
bun add @cortiqa/sdk🚀 Quickstart
Set your API key in your environment:
export CORTIQA_API_KEY="sk-cortiqa-your-api-key"Option A: Anthropic-Style (client.messages.create)
import Cortiqa from "@cortiqa/sdk";
const client = new Cortiqa();
const message = await client.messages.create({
model: "falin-01",
max_tokens: 1024,
messages: [
{ role: "user", content: "Explain quantum computing in two sentences." }
],
});
console.log(message.content);Option B: OpenAI-Style (client.chat.completions.create)
import Cortiqa from "@cortiqa/sdk";
const client = new Cortiqa();
const completion = await client.chat.completions.create({
model: "falin-01",
messages: [
{ role: "system", content: "You are an AI assistant by Cortiqa." },
{ role: "user", content: "Hello!" }
],
});
console.log(completion.choices[0].message.content);🌊 Real-Time Streaming
Effortlessly stream tokens using the built-in textStream() helper:
import Cortiqa from "@cortiqa/sdk";
const client = new Cortiqa();
const stream = await client.messages.stream({
model: "falin-01",
messages: [{ role: "user", content: "Write a poem about Mumbai." }],
});
for await (const token of stream.textStream()) {
process.stdout.write(token);
}
const finalMessage = stream.getFinalMessage();
console.log(`\nTokens used: ${finalMessage.usage?.total_tokens}`);🛠️ Tool Calling (Function Calling)
Cortiqa Falin models support structured tool execution:
import Cortiqa, { Tool } from "@cortiqa/sdk";
const client = new Cortiqa();
const tools: Tool[] = [
{
type: "function",
function: {
name: "get_weather",
description: "Get temperature for a city",
parameters: {
type: "object",
properties: {
city: { type: "string" },
},
required: ["city"],
},
},
},
];
const response = await client.messages.create({
model: "falin-01",
messages: [{ role: "user", content: "What is the weather in Delhi?" }],
tools,
});
if (response.choices[0].message.tool_calls) {
console.log("Tool requested:", response.choices[0].message.tool_calls);
}🌐 Runtime Support
The SDK uses standard Web APIs (fetch, AbortController, ReadableStream) and runs out-of-the-box on:
- Node.js (18+)
- Next.js (App Router & Server Actions)
- Vercel Edge Functions
- Cloudflare Workers
- Bun & Deno
- Browsers
⚙️ Configuration
const client = new Cortiqa({
apiKey: "sk-cortiqa-...", // Defaults to process.env.CORTIQA_API_KEY
baseURL: "https://api.cortiqa.co", // Defaults to https://api.cortiqa.co
timeout: 60_000, // 60 seconds
maxRetries: 2, // Retries on 429/5xx errors
});🛡️ Error Handling
import Cortiqa, { AuthenticationError, RateLimitError, APIError } from "@cortiqa/sdk";
const client = new Cortiqa();
try {
const response = await client.messages.create({
model: "falin-01",
messages: [{ role: "user", content: "Hi" }],
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error("Invalid API Key!");
} else if (error instanceof RateLimitError) {
console.error("Rate limit hit! Back off requests.");
} else if (error instanceof APIError) {
console.error(`API Error ${error.status}: ${error.message}`);
}
}📄 Documentation Links
📄 License
MIT © Cortiqa AI
