> For the complete documentation index, see [llms.txt](https://docs.iotex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iotex.io/quicksilver/developers/sdk-integrations/javascript.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
