Quick Start

Get started with the HOLE Foundation API in under 5 minutes.

Prerequisites

  • Node.js 18+ (for TypeScript) or Python 3.8+ (for Python)
  • Auth0 credentials (contact api@theholefoundation.org)
  • Basic knowledge of REST APIs

Step 1: Install SDK

$npm install @hole-foundation/api

Step 2: Get Access Token

For this quickstart, we’ll use the Machine-to-Machine flow:

$curl -X POST "https://dev-4fszoklachwdh46m.us.auth0.com/oauth/token" \
> -H "Content-Type: application/json" \
> -d '{
> "grant_type": "client_credentials",
> "client_id": "YOUR_M2M_CLIENT_ID",
> "client_secret": "YOUR_M2M_CLIENT_SECRET",
> "audience": "https://api.theholefoundation.org"
> }'

Save the access_token from the response.

Step 3: Initialize Client

1import { HoleFoundationClient } from '@hole-foundation/api';
2
3const client = new HoleFoundationClient({
4 environment: 'https://api.theholefoundation.org',
5 token: 'YOUR_ACCESS_TOKEN'
6});

Step 4: Make Your First API Call

Let’s search for information about FOIA exemptions:

1// Search for FOIA exemptions
2const results = await client.vectorSearch.search({
3 query: "What are the FOIA exemptions for national security?",
4 limit: 5,
5 includeContext: true
6});
7
8console.log(`Found ${results.results?.length || 0} documents`);
9
10results.results?.forEach((result, i) => {
11 console.log(`${i + 1}. ${result.title}`);
12 console.log(` Score: ${result.score?.toFixed(2)}`);
13 console.log(` Excerpt: ${result.excerpt}\n`);
14});

Step 5: Explore Transparency Data

List all US jurisdictions with transparency laws:

1const jurisdictions = await client.transparency.listJurisdictions({
2 limit: 10
3});
4
5jurisdictions.forEach(j => {
6 console.log(`${j.name} (${j.type})`);
7 console.log(` Rights: ${j.rightsCount}`);
8 console.log(` Exemptions: ${j.exemptionsCount}\n`);
9});

Step 6: Chat with AI Assistant

Get answers to legal questions:

1// Non-streaming chat
2const response = await client.chat.sendMessage({
3 message: "What is the Freedom of Information Act?",
4 stream: false
5});
6
7console.log(response.message);
8
9// Streaming chat
10const streamResponse = await client.chat.sendMessage({
11 message: "Explain FOIA exemption (b)(6)",
12 stream: true
13});
14
15// Handle stream chunks
16for await (const chunk of streamResponse) {
17 process.stdout.write(chunk);
18}

Complete Example

Here’s a complete working example that ties everything together:

1import { HoleFoundationClient } from '@hole-foundation/api';
2
3async function main() {
4 // 1. Initialize client
5 const client = new HoleFoundationClient({
6 environment: 'https://api.theholefoundation.org',
7 token: process.env.AUTH0_TOKEN!
8 });
9
10 console.log('πŸš€ HOLE Foundation API Quick Start\n');
11
12 // 2. Check API health
13 const health = await client.health.check();
14 console.log(`βœ… API Status: ${health.status}`);
15 console.log(` Version: ${health.version}\n`);
16
17 // 3. Search for documents
18 console.log('πŸ“š Searching for FOIA exemptions...');
19 const searchResults = await client.vectorSearch.search({
20 query: "FOIA exemptions for national security",
21 limit: 3
22 });
23
24 searchResults.results?.forEach((result, i) => {
25 console.log(` ${i + 1}. ${result.title} (${result.score?.toFixed(2)})`);
26 });
27
28 // 4. List jurisdictions
29 console.log('\nπŸ—ΊοΈ Transparency Jurisdictions:');
30 const jurisdictions = await client.transparency.listJurisdictions({
31 limit: 5
32 });
33
34 jurisdictions.forEach(j => {
35 console.log(` - ${j.name}`);
36 });
37
38 // 5. Chat with AI
39 console.log('\nπŸ’¬ Asking AI about FOIA...');
40 const chatResponse = await client.chat.sendMessage({
41 message: "What is FOIA in one sentence?",
42 stream: false
43 });
44
45 console.log(` ${chatResponse.message}\n`);
46
47 console.log('βœ… Quick start complete!');
48}
49
50main().catch(console.error);

Next Steps

Now that you’ve made your first API calls, explore more:

Learn About Authentication

Explore API Features

SDK Documentation

API Reference

Need Help?

Code Examples

Browse complete example projects: