Skip to main content

Quick Start Guide

Get started with Neuredge AI in minutes. Our platform offers state-of-the-art AI capabilities with OpenAI-compatible endpoints and multiple model options.

Installation

JavaScript/TypeScript

npm install @neuredge/sdk
# or
yarn add @neuredge/sdk
# or
pnpm add @neuredge/sdk

Python

pip install neuredge-sdk
# or
poetry add neuredge-sdk

Authentication

Sign up at Neuredge Dashboard to get your API key.

// JavaScript/TypeScript
import { Neuredge } from '@neuredge/sdk';

const neuredge = new Neuredge({
apiKey: 'your-api-key'
});
# Python
from neuredge import Neuredge

neuredge = Neuredge(api_key='your-api-key')

OpenAI Compatibility

Our APIs are compatible with OpenAI's SDK. Simply update the base URL:

import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: 'your-neuredge-key',
baseURL: 'https://api.neuredge.dev/v1/'
});

Basic Examples

1. Text Generation

// Using OpenAI SDK
const completion = await openai.chat.completions.create({
model: '@cf/meta/llama-3.1-8b-instruct',
messages: [
{role: 'user', content: 'What is artificial intelligence?'}
]
});

console.log(completion.choices[0].message.content);

// Using Native SDK
const response = await neuredge.generate({
model: '@cf/meta/llama-3.1-8b-instruct',
messages: [
{role: 'user', content: 'What is artificial intelligence?'}
]
});

2. Embeddings

// Using OpenAI SDK
const embedding = await openai.embeddings.create({
model: '@cf/baai/bge-base-en-v1.5',
input: 'Hello, world!'
});

// Using Native SDK
const vector = await neuredge.embeddings({
model: '@cf/baai/bge-base-en-v1.5',
input: 'Hello, world!'
});

3. Image Generation

// Using Native SDK
const image = await neuredge.generateImage({
model: '@cf/stabilityai/stable-diffusion-xl-base-1.0',
prompt: 'A serene landscape with mountains and a lake',
width: 1024,
height: 1024
});

Rate Limits & Quotas

PlanText TokensImagesEmbeddings
Free300K/month50/month300K/month
Pro ($29)3M/month500/month3M/month
Business ($49)4.5M/month750/month4.5M/month

Code Examples

Express.js API

import express from 'express';
import OpenAI from 'openai';

const app = express();
app.use(express.json());

const openai = new OpenAI({
apiKey: process.env.NEUREDGE_API_KEY,
baseURL: 'https://api.neuredge.dev/v1/'
});

app.post('/chat', async (req, res) => {
try {
const { messages } = req.body;
const completion = await openai.chat.completions.create({
model: '@cf/meta/llama-3.1-8b-instruct',
messages
});

res.json({
response: completion.choices[0].message.content
});
} catch (error) {
res.status(500).json({ error: error.message });
}
});

Next.js API Route

// pages/api/generate.js
import OpenAI from 'openai';

const openai = new OpenAI({
apiKey: process.env.NEUREDGE_API_KEY,
baseURL: 'https://api.neuredge.dev/v1/'
});

export default async function handler(req, res) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method not allowed' });
}

try {
const { prompt } = req.body;
const completion = await openai.chat.completions.create({
model: '@cf/meta/llama-3.1-8b-instruct',
messages: [{ role: 'user', content: prompt }]
});

res.status(200).json({
result: completion.choices[0].message.content
});
} catch (error) {
res.status(500).json({ error: error.message });
}
}

Best Practices

  1. Error Handling
try {
const response = await openai.chat.completions.create({
model: '@cf/meta/llama-3.1-8b-instruct',
messages: [{ role: 'user', content: prompt }]
});
} catch (error) {
if (error.code === 'rate_limit_exceeded') {
// Implement backoff strategy
} else if (error.code === 'token_limit_exceeded') {
// Handle token limit
} else {
// Handle other errors
}
}
  1. Environment Setup
// .env
NEUREDGE_API_KEY=your-api-key

// Next.js
export const runtime = 'edge' // Optional: Use edge runtime
  1. Response Streaming
const stream = await openai.chat.completions.create({
model: '@cf/meta/llama-3.1-8b-instruct',
messages: [{ role: 'user', content: prompt }],
stream: true
});

for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}

Next Steps

Explore our detailed documentation:

Or check out: