# JavaScript

## JavaScript Integration

QuickSilver supports JavaScript integration using the [OpenAI client library](https://www.npmjs.com/package/openai), offering full support for async/await and compatibility with modern web applications.

### Installation

```bash
npm install openai
```

### Usage

```javascript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.iotex.io/quicksilver/developers/sdk-integrations/javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
