JavaScript
JavaScript Integration
QuickSilver supports JavaScript integration using the OpenAI client library, offering full support for async/await and compatibility with modern web applications.
Installation
npm install openai
Usage
import OpenAI from "openai";
// Initialize the client
const openai = new OpenAI({
apiKey: "your-api-key", // Use your Agent ID as the API Key
baseURL: "https://api-quicksilver.iotex.ai/v1", // QuickSilver API endpoint
});
// Prepare Actor input
const runInput = {
model: "gpt-3.5-turbo",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Tell me about OpenAPI schemas." }
],
temperature: 0.7
};
// Run the conversation
async function main() {
const response = await openai.chat.completions.create(runInput);
// Process the response
console.log(response.choices[0].message.content);
}
main();
Tips
Built-in support for async/await simplifies integration in modern JavaScript and TypeScript projects.
Multi-turn conversations are supported by appending to the messages array.
Fully compatible with OpenAI’s chat.completions interface — no changes needed beyond the base URL.
Keep your API key secure. Do not expose it in frontend code or public repositories.
Last updated