Quick Start
This guide will help you make your first API call with the Exnest AI SDK.
Prerequisites
Section titled “Prerequisites”Before you begin, make sure you have:
- An Exnest AI API Key (Get one from the Exnest Dashboard)
- Node.js 18+ or Python 3.8+ installed
Making Your First Request
Section titled “Making Your First Request”Using the Advanced Client (Recommended)
Section titled “Using the Advanced Client (Recommended)”The ExnestAI client provides full control over configuration, retries, and access to all features including EBC.
import { ExnestAI } from '@exnest-dev/ai';
const exnest = new ExnestAI({ apiKey: 'your-api-key', baseUrl: 'https://api.exnest.app/v1', // Optional timeout: 30000, // Optional retries: 3, // Optional retryDelay: 1000, // Optional debug: true // Optional});
// Simple chat completionconst response = await exnest.chat('gpt-4.1-mini', [ { role: 'user', content: 'Hello, how are you?' }]);
console.log(response.data.choices[0].message.content);Using the Simple Wrapper
Section titled “Using the Simple Wrapper”For quick and simple use cases.
import { ExnestWrapper } from '@exnest-dev/ai';
const exnest = new ExnestWrapper('your-api-key');
// Simple responseconst response = await exnest.response('claude-3-haiku', 'What is TypeScript?');console.log(response.data.choices[0].message.content);Using the Advanced Client (Recommended)
Section titled “Using the Advanced Client (Recommended)”For full control over configuration, retries, timeouts, and access to EBC (Exnest Brain Core) features.
import asyncioimport osfrom exnestai import ExnestAI, ExnestMessage
async def main(): api_key = os.getenv("EXNEST_API_KEY")
# Initialize the advanced client client = ExnestAI( api_key=api_key, timeout=60000, # 60 seconds retries=2, debug=True )
# --- Standard Chat --- chat_response = await client.chat( model="openai:gpt-4o-mini", messages=[ExnestMessage(role="user", content="Hello! What can you tell me about ExnestAI?")], exnest_metadata=True ) if not chat_response.error: print(f"Chat Response: {chat_response.choices[0].message.content}")
if __name__ == "__main__": asyncio.run(main())Using the Simple Wrapper
Section titled “Using the Simple Wrapper”For straightforward use cases.
import asyncioimport osfrom exnestai import ExnestWrapper, ExnestMessage
async def main(): # Initialize the wrapper api_key = os.getenv("EXNEST_API_KEY") exnest = ExnestWrapper(api_key=api_key)
# Perform a chat completion chat_response = await exnest.chat( model="openai:gpt-4o-mini", messages=[ExnestMessage(role="user", content="Hello, how are you?")] ) if not chat_response.error: print(f"Wrapper Chat Response: {chat_response.choices[0].message.content}")
if __name__ == "__main__": asyncio.run(main())Using LangChain (or other OpenAI-compatible clients)
Section titled “Using LangChain (or other OpenAI-compatible clients)”You can use standard OpenAI-compatible clients by pointing the baseURL to Exnest’s API.
import { ChatOpenAI } from "@langchain/openai";
export function createLLM(options: AIServiceOptions = {}) { const apiKey = config.exnestApiKey;
if (!apiKey) { throw new Error("EXNEST_API_KEY is not configured"); }
return new ChatOpenAI({ apiKey, temperature: options.temperature ?? 0.7, streaming: options.streaming ?? false, configuration: { baseURL: "https://api.exnest.app/v1", }, modelName: options.modelName ?? "gpt-4.1-mini", });}