Halfred Node.js SDK
Official Halfred SDK for Node.js and TypeScript with modern JavaScript features, full type support, and easy integration.
Installation
Install the Halfred SDK using your preferred package manager:
npm install halfred.aiyarn add halfred.aipnpm add halfred.aiQuick Start
Basic Setup
import { Halfred } from "halfred.ai";
const client = new Halfred({
apiKey: "halfred_xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});
async function main() {
const completion = await client.chat.completions.create({
model: "lite",
messages: [{ role: "user", content: "What is the capital of France?" }],
});
console.log(completion.choices[0].message.content);
}
main();With Environment Variables (Recommended)
You can also explicitly provide the API key if needed:
Chat Completions
Simple Completion
With System Message
Conversation History
With Options
Choosing a Model Profile
Halfred offers different profiles optimized for various use cases:
Learn more about profiles in our Model Profiles guide.
Response Format
JSON Mode
Request JSON-formatted responses:
JSON Schema Mode
Enforce a specific JSON structure using JSON Schema:
Error Handling
Streaming Responses (Coming Soon)
Real-time streaming support is coming soon. Contact support for early access.
List Available Models
Best Practices
1. Use Environment Variables
2. Handle Errors Gracefully
3. Choose the Right Profile
4. Monitor Token Usage
Troubleshooting
Module Not Found
TypeScript Errors
API Key Issues
Support
Documentation: https://docs.halfred.ai
Email: [email protected]
Discord: Join our community
GitHub: Report issues
Next Steps
Learn about Model Profiles
Explore the REST API Reference
Check out Best Practices
Last updated