Quick Start
Get up and running with Devcogent in just a few minutes.
Initialize Devcogent
First, initialize the Devcogent client in your application:
import { Devcogent } from '@devcogent/sdk';
const client = new Devcogent({
apiKey: 'your-api-key',
environment: 'production' // or 'development'
});
Basic Usage
Making Your First API Call
// Example: Get user data
async function getUserData(userId) {
try {
const response = await client.users.get(userId);
console.log('User data:', response.data);
return response.data;
} catch (error) {
console.error('Error fetching user:', error);
}
}
Handling Responses
// All API calls return a structured response
const response = await client.api.call();
console.log(response.data); // Your data
console.log(response.status); // HTTP status code
console.log(response.headers); // Response headers
Common Patterns
Error Handling
try {
const result = await client.someMethod();
// Handle success
} catch (error) {
if (error.status === 401) {
// Handle authentication error
} else if (error.status === 429) {
// Handle rate limiting
} else {
// Handle other errors
}
}
Pagination
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await client.getData({ page, limit: 50 });
// Process data
response.data.forEach(item => {
console.log(item);
});
hasMore = response.hasMore;
page++;
}
Examples
Complete Example
import { Devcogent } from '@devcogent/sdk';
const client = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY
});
async function main() {
try {
// Initialize connection
await client.connect();
// Perform operations
const data = await client.getData();
console.log('Retrieved data:', data);
} catch (error) {
console.error('Error:', error.message);
}
}
main();
Next Steps
- Learn about Configuration options
- Explore our API Integration Guide
- Check out Authentication methods