> ## Documentation Index
> Fetch the complete documentation index at: https://docsv2.sportxapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SDKs & Code Examples

> Implementation examples in JavaScript / TypeScript and Python for SportXAPI.

SportXAPI works out of the box with any HTTP client in any language. Below are copy-paste examples for popular runtimes.

## Node.js / TypeScript

Using native `fetch` (Node.js 18+):

```typescript theme={null}
interface ScheduleResponse {
  id: number;
  matchID: string;
  name: string;
  matchStatus: string;
  startDate: string;
}

async function getLiveMatches(): Promise<ScheduleResponse[]> {
  const apiKey = process.env.SPORTXAPI_KEY;
  if (!apiKey) throw new Error("SPORTXAPI_KEY is not defined");

  const response = await fetch("https://apiv2.sportxapi.com/cricket/api/v2/match/schedule?status=live", {
    method: "GET",
    headers: {
      "X-API-Key": apiKey,
      "Accept": "application/json"
    }
  });

  if (!response.ok) {
    throw new Error(`SportXAPI error: ${response.status} ${response.statusText}`);
  }

  return response.json();
}

getLiveMatches().then(matches => console.log("Live matches:", matches));
```

***

## Python

Using `requests`:

```python theme={null}
import os
import requests

def get_live_matches():
    api_key = os.getenv("SPORTXAPI_KEY")
    if not api_key:
        raise ValueError("Missing SPORTXAPI_KEY environment variable")

    url = "https://apiv2.sportxapi.com/cricket/api/v2/match/schedule"
    headers = {
        "X-API-Key": api_key,
        "Accept": "application/json"
    }
    params = {"status": "live"}

    response = requests.get(url, headers=headers, params=params)
    response.raise_for_status()
    return response.json()

if __name__ == "__main__":
    live_matches = get_live_matches()
    print(live_matches)
```

***

## Server-Sent Events (SSE) Stream

For realtime match score feeds without polling, use the streaming endpoint `/cricket/api/v2/match/:matchId/stream`:

```javascript theme={null}
const EventSource = require("eventsource");

const matchId = "100123";
const apiKey = process.env.SPORTXAPI_KEY;

const stream = new EventSource(`https://apiv2.sportxapi.com/cricket/api/v2/match/${matchId}/stream`, {
  headers: { "X-API-Key": apiKey }
});

stream.onmessage = (event) => {
  const payload = JSON.parse(event.data);
  console.log("Realtime match update:", payload);
};

stream.onerror = (err) => {
  console.error("SSE stream error:", err);
};
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.