Skip to main content
The SDK supports two approaches for browser/frontend usage. Choose the one that matches your build tooling.
Never embed private API keys, secrets, or passphrases in frontend code. Any credentials included in a browser bundle are visible to anyone who views the page source. Restrict browser usage to public API endpoints only.
This is the modern approach. Import the SDK directly into your frontend project with full TypeScript support. It requires polyfilling a couple of Node.js built-ins that browsers do not provide natively.

Option 2: Webpack bundle (script tag)

This is the legacy approach for including the SDK on a plain HTML page via a <script> tag. It produces a minified UMD bundle in the dist/ directory.

Caveats

The keepAlive option on RestClientOptions uses Node.js’s https.Agent, which is not available in browsers. This option is silently ignored in browser environments.
  • No private keys in the browser. Use a server-side proxy if you need to make authenticated requests from a web application.
  • CORS: OKX’s API endpoints may not allow direct browser requests from all origins. Check their CORS policy before building browser-based integrations.
  • Bundle size: The webpack bundle includes the full SDK. Use tree-shaking via the TypeScript import approach if bundle size is a concern.