JavaScript SDK Client Setup
Initialize and configure the Enterprise API client for your JavaScript/TypeScript application.
Basic Initialization
Create a client with just your API key:
import { EnterpriseClient } from '@gridbank/api-js';
const client = new EnterpriseClient({ apiKey: 'apik_your_key_here' });
Get your API key: Contact support@gridbank.io — keys are provisioned manually during onboarding.
Configuration Options
Customize client behavior with advanced options:
const client = new EnterpriseClient({
apiKey: 'apik_your_key_here',
baseUrl: 'https://api2.gridbank.io', // Default API endpoint
});
Secure API Key Management (Recommended)
Never hardcode API keys. Store them in environment variables.
For Vite/React:
# .env file
VITE_GRIDBANK_API_KEY=apik_your_key_here
const apiKey = import.meta.env.VITE_GRIDBANK_API_KEY;
if (!apiKey) {
throw new Error('VITE_GRIDBANK_API_KEY environment variable not set');
}
const client = new EnterpriseClient({ apiKey });
For Node.js:
# .env file or export in terminal
export GRIDBANK_API_KEY=apik_your_key_here
const apiKey = process.env.GRIDBANK_API_KEY;
if (!apiKey) {
throw new Error('GRIDBANK_API_KEY environment variable not set');
}
const client = new EnterpriseClient({ apiKey });
Error Handling
All SDK methods throw EnterpriseAPIError on API errors. Handle them gracefully:
import { EnterpriseClient, EnterpriseAPIError } from '@gridbank/api-js';
const client = new EnterpriseClient({ apiKey: 'apik_...' });
try {
const results = await client.searchVideos({ q: 'test' });
} catch (error) {
if (error instanceof EnterpriseAPIError) {
console.error(`HTTP ${error.statusCode}: ${error.message}`);
if (error.details) {
console.error('Details:', error.details);
}
} else {
console.error('Unexpected error:', error);
}
}
See Error Handling Guide for detailed error information.
TypeScript Support
Full type definitions are included for excellent IDE support:
import { EnterpriseClient, VideoListResponse, Video } from '@gridbank/api-js';
const client = new EnterpriseClient({ apiKey: 'apik_...' });
// Full type inference
const results: VideoListResponse = await client.searchVideos({
q: 'nature',
per_page: 5
});
// IDE autocomplete for all properties
results.videos.forEach((video: Video) => {
console.log(`${video.title} by ${video.creator.name}`);
});
Next Steps
- Method Reference — Complete method documentation
- Code Examples — Real-world usage patterns
- Error Handling — Learn error codes