Get API key

Getting Started

Learn how to access, configure, and use Pyth Pro price feeds

Pyth Pro is a high-performance, low-latency service that provides real-time financial market data. This guide will walk you through setting up and running a basic JavaScript example to subscribe to Pyth Pro price feeds.

Try a Live Stream

This preview subscribes to three feeds on the Fixed 200ms channel.

Fixed 200ms · Price, Feed Update Timestamp
AAPLPYTH PRICE IN USD FOR APPLE 24/7 · Equity
—
Change since Run
—
Timestamp
—
EURUSDEURO / US DOLLAR · FX
—
Change since Run
—
Timestamp
—
BTCUSDBITCOIN / US DOLLAR · Crypto
—
Change since Run
—
Timestamp
—
Ready

Press Run to stream. Messages arrive like this one:

The preview uses a shared demo key, which is rate-limited, and each stream stops after ten seconds. For other feeds, properties or channels, open the Pyth Playground.

Get an API Key

Your own app needs a Pyth Pro API key. To request one, follow Acquire an API Key.

Run the Code

This code opens the same stream from your app, in TypeScript, Python or Go, or as a wscat command. Set the PYTH_PRO_API_KEY environment variable to your API key, then run it.

pyth-pro-example.ts
// Requirements: Node.js 24 or later
//   npm install @pythnetwork/pyth-lazer-sdk
//   npm pkg set type=module
//
// Usage:
//   node pyth-pro-example.ts

import { PythLazerClient } from "@pythnetwork/pyth-lazer-sdk";

// Read your API key from the environment (never hard-code it)
const token = process.env.PYTH_PRO_API_KEY;
if (!token) throw new Error("Set PYTH_PRO_API_KEY in your environment");

// Create the Pyth Pro client with WebSocket pool configuration
const client = await PythLazerClient.create({
  token,
  webSocketPoolConfig: {
    urls: [
      "wss://pyth-lazer-0.dourolabs.app/v1/stream",
      "wss://pyth-lazer-1.dourolabs.app/v1/stream",
      "wss://pyth-lazer-2.dourolabs.app/v1/stream",
    ],
  },
});

// Subscribe to price feeds
client.subscribe({
  type: "subscribe",
  subscriptionId: 1,
  priceFeedIds: [3191, 327, 1],
  properties: ["price", "feedUpdateTimestamp"],
  formats: ["solana"],
  channel: "fixed_rate@200ms",
  deliveryFormat: "json",
  jsonBinaryEncoding: "hex",
  parsed: true,
  ignoreInvalidFeeds: true, // Ignore invalid feed IDs instead of failing
});

// Listen for price updates
client.addMessageListener((message) => {
  if (message.type === "json") {
    console.log("Received JSON update:", JSON.stringify(message.value, null, 2));
  } else {
    console.log("Received binary update:", {
      subscriptionId: message.value.subscriptionId,
      parsed: message.value.parsed,
    });
  }
});

// Handle connection errors
client.addAllConnectionsDownListener(() => {
  console.error("All WebSocket connections are down!");
});

// To unsubscribe later:
// client.unsubscribe(1);

// To shutdown the client:
// client.shutdown();

Pyth Pro was previously known as Pyth Lazer. The SDK remains the same.

Production Tip: Include feedUpdateTimestamp

For production applications, add "feedUpdateTimestamp" to the properties array. This field lets you determine whether a price was freshly generated or carried forward from an earlier update by comparing it against timestampUs. See Payload Reference — Price Availability Semantics for details.

For a detailed explanation of every property passed to client.subscribe, see the Payload Reference.

What's Next?

Now that you've successfully run the basic Pyth Pro example, you can explore more advanced integration patterns:

More Information

Explore additional Pyth Pro capabilities:

Blockchain Integration

Learn how to integrate Pyth Pro price feeds into your smart contracts:

  • Solana Integration - Build SVM smart contracts that consume Pyth Pro price feeds with cryptographic verification
  • EVM Integration - Integrate Pyth Pro into Ethereum and other EVM-compatible chains
  • Sui Integration - Verify Pyth Pro price updates in Sui Programmable Transaction Blocks before consuming them in Move contracts
  • IOTA Integration - Verify Pyth Pro price updates in IOTA Programmable Transaction Blocks before consuming them in Move contracts
  • Cardano Integration - Verify Pyth Pro price updates in Cardano transactions

AI-Assisted Development

Use Pyth market data directly in AI assistants like Claude, Cursor, and Windsurf via the Model Context Protocol:

  • MCP Server - Connect your AI assistant to Pyth price feeds, historical data, and candlestick charts
  • MCP Skills - Pre-built workflows for portfolio tracking, volatility analysis, FX conversion, and more

Example Applications

Check out more comprehensive examples in the pyth-examples repository:

  • Solana Examples - Post price data to Solana smart contracts with Ed25519 and ECDSA verification
  • EVM Examples - Smart contract integration for Ethereum-compatible chains