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

# Credits

> Check your remaining credit balance

Check your remaining API credit balance at any time without consuming credits.

<Info>
  **Cost:** Free (0 credits)
</Info>

<Note>
  **Interactive Playground:** Test this endpoint in the [API Playground](/api-reference/credits). Get your API key at [data.octav.fi](https://data.octav.fi/)
</Note>

***

## Endpoint

```bash theme={null}
GET https://api.octav.fi/v1/credits
```

## No parameters required.

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://api.octav.fi/v1/credits" \
    -H "Authorization: Bearer YOUR_API_KEY"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.octav.fi/v1/credits', {
    headers: {
      'Authorization': `Bearer ${apiKey}`
    }
  });

  const credits = await response.json();
  console.log(`Remaining credits: ${credits}`);
  ```

  ```python Python theme={null}
  response = requests.get(
      'https://api.octav.fi/v1/credits',
      headers={'Authorization': f'Bearer {api_key}'}
  )

  credits = response.json()
  print(f'Remaining credits: {credits}')
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch('https://api.octav.fi/v1/credits', {
    headers: {
      'Authorization': `Bearer ${apiKey}`
    }
  });

  const credits: number = await response.json();
  console.log(`Remaining credits: ${credits}`);
  ```
</CodeGroup>

***

## Response

Returns a simple number representing your remaining credits.

```json theme={null}
19033
```

***

## Use Cases

<Tabs>
  <Tab title="Monitor Balance" icon="gauge">
    Check credits before expensive operations:

    ```javascript theme={null}
    async function checkCreditsBeforeSync(address) {
      // Check available credits
      const response = await fetch('https://api.octav.fi/v1/credits', {
        headers: { 'Authorization': `Bearer ${apiKey}` }
      });
      const credits = await response.json();

      console.log(`Available credits: ${credits}`);

      // Estimate sync cost (rough estimate)
      const statusResponse = await fetch(
        `https://api.octav.fi/v1/status?addresses=${address}`,
        { headers: { 'Authorization': `Bearer ${apiKey}` } }
      );
      const [status] = await statusResponse.json();

      if (credits < 50) {
        console.warn('Low credits! Consider purchasing more.');
        return false;
      }

      // Proceed with sync
      await fetch('https://api.octav.fi/v1/sync-transactions', {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${apiKey}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ addresses: [address] })
      });

      return true;
    }
    ```
  </Tab>

  <Tab title="Alert on Low Balance" icon="bell">
    Set up alerts for low credit balance:

    ```javascript theme={null}
    async function monitorCredits(threshold = 1000) {
      const response = await fetch('https://api.octav.fi/v1/credits', {
        headers: { 'Authorization': `Bearer ${apiKey}` }
      });

      const credits = await response.json();

      if (credits < threshold) {
        console.warn(`⚠️  Low credit balance: ${credits}`);
        console.warn(`Purchase more at https://data.octav.fi/`);

        // Send notification (email, Slack, etc.)
        await sendAlert({
          message: `API credits low: ${credits} remaining`,
          severity: 'warning'
        });
      } else {
        console.log(`✓ Credit balance healthy: ${credits}`);
      }

      return credits;
    }

    // Run periodically
    setInterval(() => monitorCredits(1000), 3600000); // Every hour
    ```
  </Tab>

  <Tab title="Track Usage" icon="chart-line">
    Track credit consumption over time:

    ```javascript theme={null}
    class CreditTracker {
      constructor(apiKey) {
        this.apiKey = apiKey;
        this.snapshots = [];
      }

      async snapshot() {
        const response = await fetch('https://api.octav.fi/v1/credits', {
          headers: { 'Authorization': `Bearer ${this.apiKey}` }
        });

        const credits = await response.json();
        const snapshot = {
          timestamp: new Date().toISOString(),
          credits
        };

        this.snapshots.push(snapshot);
        return snapshot;
      }

      getUsageSince(timestamp) {
        const snapshots = this.snapshots.filter(
          s => new Date(s.timestamp) >= new Date(timestamp)
        );

        if (snapshots.length < 2) return 0;

        return snapshots[0].credits - snapshots[snapshots.length - 1].credits;
      }

      async getCurrentUsageRate() {
        // Take snapshots 1 minute apart
        const snapshot1 = await this.snapshot();
        await new Promise(resolve => setTimeout(resolve, 60000));
        const snapshot2 = await this.snapshot();

        const creditsUsed = snapshot1.credits - snapshot2.credits;
        const creditsPerHour = creditsUsed * 60;

        console.log(`Usage rate: ${creditsUsed} credits/min`);
        console.log(`Projected: ${creditsPerHour} credits/hour`);
        console.log(`Days remaining: ${(snapshot2.credits / (creditsPerHour * 24)).toFixed(1)}`);

        return {
          creditsPerMinute: creditsUsed,
          creditsPerHour,
          daysRemaining: snapshot2.credits / (creditsPerHour * 24)
        };
      }
    }

    const tracker = new CreditTracker(apiKey);
    const usage = await tracker.getCurrentUsageRate();
    ```
  </Tab>

  <Tab title="Budget Management" icon="dollar-sign">
    Implement credit budgets:

    ```javascript theme={null}
    class CreditBudget {
      constructor(apiKey, dailyBudget) {
        this.apiKey = apiKey;
        this.dailyBudget = dailyBudget;
        this.startCredits = null;
        this.startDate = null;
      }

      async initialize() {
        const response = await fetch('https://api.octav.fi/v1/credits', {
          headers: { 'Authorization': `Bearer ${this.apiKey}` }
        });

        this.startCredits = await response.json();
        this.startDate = new Date();

        console.log(`Budget initialized: ${this.dailyBudget} credits/day`);
        console.log(`Starting balance: ${this.startCredits}`);
      }

      async checkBudget() {
        const response = await fetch('https://api.octav.fi/v1/credits', {
          headers: { 'Authorization': `Bearer ${this.apiKey}` }
        });

        const currentCredits = await response.json();
        const usedToday = this.startCredits - currentCredits;
        const remainingBudget = this.dailyBudget - usedToday;

        console.log(`Used today: ${usedToday}/${this.dailyBudget}`);
        console.log(`Remaining budget: ${remainingBudget}`);

        if (remainingBudget <= 0) {
          throw new Error('Daily credit budget exceeded!');
        }

        return {
          used: usedToday,
          remaining: remainingBudget,
          percentage: (usedToday / this.dailyBudget * 100).toFixed(2)
        };
      }
    }

    const budget = new CreditBudget(apiKey, 1000); // 1000 credits/day
    await budget.initialize();
    const status = await budget.checkBudget();
    ```
  </Tab>
</Tabs>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Check Regularly" icon="arrows-rotate">
    Since this endpoint is free, check it liberally:

    * Before expensive operations
    * In application health checks
    * When displaying usage stats to users
  </Accordion>

  <Accordion title="Set Up Alerts" icon="bell">
    Implement automated alerts:

    * Alert at 20% remaining
    * Warning at 10% remaining
    * Critical at 5% remaining
  </Accordion>

  <Accordion title="Plan Ahead" icon="calendar">
    Monitor consumption patterns:

    * Track daily usage
    * Forecast when credits will run out
    * Purchase credits before running low
  </Accordion>
</AccordionGroup>

***

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Pricing" icon="tag" href="/api/pricing">
    View credit packages and pricing
  </Card>

  <Card title="Status" icon="signal" href="/api/endpoints/status">
    Check sync status (also free)
  </Card>

  <Card title="Developer Portal" icon="laptop-code" href="https://data.octav.fi/">
    Purchase more credits
  </Card>
</CardGroup>
