You've heard about AI SDKs but aren't sure where to start. Let's fix that.
Imagine you want to add AI to your app -- maybe a chatbot, maybe a smart search feature. You might think you need days of setup, a PhD in machine learning, and three different API accounts. The truth is, you can get a working AI call running in under 5 minutes with NeuroLink. No prior AI experience needed.
NeuroLink (@juspay/neurolink
) handles all the complicated provider stuff behind the scenes. You just write a few lines of TypeScript, and it works with any major AI provider -- OpenAI, Google, Anthropic, and more.
In this post, you will learn:
flowchart LR
A["npm install<br/>@juspay/neurolink"] --> B["Configure<br/>.env API key"]
B --> C["Import &<br/>Instantiate"]
C --> D["Call<br/>generate()"]
D --> E["AI Response"]
style A fill:#0f4c75,stroke:#1b262c,color:#fff
style B fill:#0f4c75,stroke:#1b262c,color:#fff
style C fill:#3282b8,stroke:#1b262c,color:#fff
style D fill:#3282b8,stroke:#1b262c,color:#fff
style E fill:#00b4d8,stroke:#1b262c,color:#fff
Before you begin, make sure you have the following:
node --version
.
Tip:Not sure which provider to pick? Think of it like choosing a phone carrier -- they all do the same basic thing, just with different pricing. OpenAI (gpt-4o
) has the biggest community, while Google AI Studio (gemini-2.5-flash
) lets you get started for free.
{: .prompt-tip }
Start with a fresh directory and initialize a Node.js project configured for ES modules:
mkdir my-ai-app && cd my-ai-app
npm init -y
Update your package.json
to enable ES module support:
{
"name": "my-ai-app",
"type": "module",
"scripts": {
"start": "npx tsx src/index.ts"
}
}
Install the SDK with a single command:
npm install @juspay/neurolink
If you are using TypeScript (recommended), also install tsx for running TypeScript directly:
npm install -D tsx typescript
Create a tsconfig.json
at the project root:
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"outDir": "./dist"
},
"include": ["src/**/*"]
}
Create a .env
file at the project root with your provider's API key. NeuroLink auto-loads dotenv, so no additional configuration is needed:
OPENAI_API_KEY=sk-your-key-here
ANTHROPIC_API_KEY=sk-ant-your-key-here
GOOGLE_AI_API_KEY=your-google-key-here
VERTEX_PROJECT_ID=your-gcp-project-id
You only need one provider key to get started. Add more later when you want to explore multi-provider features.
Warning:Your.env
file contains secret API keys -- treat it like a password. Never commit it to Git. Add.env
to your.gitignore
file right away.
{: .prompt-warning }
Create src/index.ts
and write your first AI generation:
import { NeuroLink } from '@juspay/neurolink';
const neurolink = new NeuroLink();
const result = await neurolink.generate({
input: { text: 'Explain quantum computing in simple terms' },
provider: 'openai',
model: 'gpt-4o'
});
console.log(result.content);
console.log(`Tokens used: ${result.usage?.total}`);
console.log(`Response time: ${result.responseTime}ms`);
Run it:
npm start
That is it. Five lines of meaningful code, and you have a working AI application.
Let us break down what each part does.
** GenerateOptions** -- the object you pass to
generate()
:| Field | Type | Description |
|---|---|---|
input.text |
string |
The prompt or question for the AI model |
provider |
string |
Which AI provider to use (e.g., 'openai' , 'anthropic' , 'vertex' ) |
model |
string |
The specific model to use (e.g., 'gpt-4o' , 'claude-sonnet-4-5-20250929' ) |
temperature |
number |
Creativity control: 0 = deterministic, 1 = creative (optional) |
maxTokens |
number |
Maximum tokens in the response (optional) |
systemPrompt |
string |
Instructions that shape the AI's behavior (optional) |
** GenerateResult** -- the object you get back:
| Field | Type | Description |
|---|---|---|
content |
||
string |
||
| The AI's response text | ||
provider |
||
string |
||
| Which provider was used | ||
model |
||
string |
||
| Which model was used | ||
usage.total |
||
number |
||
| Total tokens consumed | ||
usage.input |
||
number |
||
| Tokens in the input prompt | ||
usage.output |
||
number |
||
| Tokens in the output response | ||
responseTime |
||
number |
||
| Time in milliseconds |
Note:Token usage fields usetotal
,input
, andoutput
-- nottotalTokens
orinputTokens
. This is a deliberate normalization across providers.
{: .prompt-info }
Here is the power of a unified SDK. The same code works with any provider -- just change the provider
and model
strings:
import { NeuroLink } from '@juspay/neurolink';
const neurolink = new NeuroLink();
// OpenAI
const openaiResult = await neurolink.generate({
input: { text: 'What is machine learning?' },
provider: 'openai',
model: 'gpt-4o'
});
// Anthropic Claude
const anthropicResult = await neurolink.generate({
input: { text: 'What is machine learning?' },
provider: 'anthropic',
model: 'claude-sonnet-4-5-20250929'
});
// Google Vertex AI
const vertexResult = await neurolink.generate({
input: { text: 'What is machine learning?' },
provider: 'vertex',
model: 'gemini-3-flash'
});
// AWS Bedrock
const bedrockResult = await neurolink.generate({
input: { text: 'What is machine learning?' },
provider: 'bedrock',
model: 'anthropic.claude-3-sonnet-20240229-v1:0'
});
Note:Model names and IDs in code examples reflect versions available at time of writing. Model availability, naming conventions, and pricing change frequently. Always verify current model IDs with your provider's documentation before deploying to production.
{: .prompt-info }
Every call returns the same GenerateResult
type. Your application code that processes the response does not need to change at all.
flowchart TD
A["neurolink.generate()"] --> B{"provider?"}
B -->|"openai"| C["OpenAI GPT-4o"]
B -->|"anthropic"| D["Claude Sonnet"]
B -->|"vertex"| E["Gemini Flash"]
B -->|"bedrock"| F["AWS Bedrock"]
B -->|"ollama"| G["Local LLM"]
C --> H["Same GenerateResult"]
D --> H
E --> H
F --> H
G --> H
style A fill:#0f4c75,stroke:#1b262c,color:#fff
style B fill:#3282b8,stroke:#1b262c,color:#fff
style H fill:#00b4d8,stroke:#1b262c,color:#fff
If you do not want to hardcode a provider, createBestAIProvider()
scans your environment variables and automatically selects the first available provider:
import { createBestAIProvider } from '@juspay/neurolink';
// Automatically uses the provider with a configured API key
const provider = await createBestAIProvider();
const result = await provider.generate({
input: { text: 'What is machine learning?' }
});
console.log(result.content);
This is especially useful for libraries and shared modules where you do not want to assume which provider your user has configured.
Here is the complete list of providers from the AIProviderName
enum:
| Provider | Config Key | Environment Variable |
|---|---|---|
| OpenAI | openai |
|
OPENAI_API_KEY |
||
| Anthropic | anthropic |
|
ANTHROPIC_API_KEY |
||
| Google Vertex AI | vertex |
|
VERTEX_PROJECT_ID |
||
| AWS Bedrock | bedrock |
|
| AWS credentials | ||
| Azure OpenAI | azure |
|
AZURE_OPENAI_API_KEY |
||
| Google AI Studio | google-ai |
|
GOOGLE_AI_API_KEY |
||
| Mistral | mistral |
|
MISTRAL_API_KEY |
||
| Ollama | ollama |
|
| (local, no key needed) | ||
| LiteLLM | litellm |
|
LITELLM_API_KEY |
||
| Hugging Face | huggingface |
|
HUGGINGFACE_API_KEY |
||
| AWS SageMaker | sagemaker |
|
| AWS credentials | ||
| OpenRouter | openrouter |
|
OPENROUTER_API_KEY |
||
| OpenAI-Compatible | openai-compatible |
|
| Configurable |
For chat interfaces and real-time applications, you want tokens to appear as they are generated rather than waiting for the complete response. Switch from generate()
to stream()
:
import { NeuroLink } from '@juspay/neurolink';
const neurolink = new NeuroLink();
const result = await neurolink.stream({
input: { text: 'Write a haiku about TypeScript' },
provider: 'anthropic',
model: 'claude-sonnet-4-5-20250929',
systemPrompt: 'You are a creative poet.',
temperature: 1.0
});
for await (const chunk of result.stream) {
if ('content' in chunk) {
process.stdout.write(chunk.content);
}
}
The result.stream
async iterator delivers text chunks as they arrive from the provider. This works identically across all 13 providers -- NeuroLink normalizes the different streaming protocols (SSE, WebSocket, HTTP chunking) into a single consistent interface.
Note:The streaming property isresult.stream
, notresult.textStream
. This is consistent across all NeuroLink streaming operations.
{: .prompt-info }
If you are building a web frontend, you can pipe the stream directly to a response:
// In an Express/Hono route handler
app.post('/chat', async (req, res) => {
const neurolink = new NeuroLink();
const result = await neurolink.stream({
input: { text: req.body.message },
provider: 'openai',
model: 'gpt-4o'
});
res.setHeader('Content-Type', 'text/event-stream');
for await (const chunk of result.stream) {
res.write(`data: ${JSON.stringify({ text: chunk })}\n\n`);
}
res.end();
});
System prompts let you shape the AI's behavior and personality. They work with both generate()
and stream()
:
import { NeuroLink } from '@juspay/neurolink';
const neurolink = new NeuroLink();
// A helpful coding assistant
const result = await neurolink.generate({
input: { text: 'How do I handle errors in async/await?' },
provider: 'openai',
model: 'gpt-4o',
systemPrompt: 'You are a senior TypeScript developer. Provide concise, practical answers with code examples. Always mention edge cases.',
temperature: 0.3 // Lower temperature for more deterministic, technical answers
});
console.log(result.content);
The temperature
parameter controls the creativity of the output:
For production applications, you want resilience. If your primary provider has an outage, you need a fallback:
import { createAIProviderWithFallback } from '@juspay/neurolink';
const { primary, fallback } = await createAIProviderWithFallback(
'openai', // Primary provider
'bedrock' // Fallback provider
);
try {
const result = await primary.generate({ input: { text: 'Hello!' } });
console.log(result.content);
} catch (error) {
const result = await fallback.generate({ input: { text: 'Hello!' } });
console.log('Fallback:', result.content);
}
This pattern ensures your application stays available even when individual providers experience issues. You can configure as many fallback layers as you need.
Congratulations -- you just built your first AI application! Let's recap what you accomplished:
npm install @juspay/neurolink
.env
generate()
stream()
That was not so scary, right? Now you have a solid foundation to build on. Here are some fun next steps depending on what interests you:
Star the NeuroLink GitHub repository, join the discussions, and let us know what you build. The npm package is available now.
Related posts: