Skip to main content

Configuration

Learn how to configure Devcogent for your specific needs and environment.

Basic Configuration

Client Options

import { Devcogent } from '@devcogent/sdk';

const client = new Devcogent({
// Required
apiKey: 'your-api-key',

// Optional configuration
environment: 'production', // 'development' | 'staging' | 'production'
timeout: 30000, // Request timeout in milliseconds
retries: 3, // Number of retry attempts
baseURL: 'https://api.devcogent.com',

// Rate limiting
rateLimit: {
requests: 100, // Requests per window
window: 60000 // Time window in milliseconds
}
});

Environment Variables

Set up environment variables for different deployment environments:

Development (.env.development)

DEVCOGENT_API_KEY=dev_key_123
DEVCOGENT_ENVIRONMENT=development
DEVCOGENT_DEBUG=true
DEVCOGENT_BASE_URL=https://dev-api.devcogent.com

Production (.env.production)

DEVCOGENT_API_KEY=prod_key_456
DEVCOGENT_ENVIRONMENT=production
DEVCOGENT_DEBUG=false
DEVCOGENT_BASE_URL=https://api.devcogent.com

Advanced Configuration

Logging

const client = new Devcogent({
apiKey: 'your-api-key',
logging: {
level: 'info', // 'debug' | 'info' | 'warn' | 'error'
destination: console, // Custom logger
format: 'json' // 'json' | 'pretty'
}
});

Custom Headers

const client = new Devcogent({
apiKey: 'your-api-key',
headers: {
'X-Custom-Header': 'value',
'User-Agent': 'MyApp/1.0'
}
});

Interceptors

// Request interceptor
client.interceptors.request.use((config) => {
config.headers['X-Request-ID'] = generateRequestId();
return config;
});

// Response interceptor
client.interceptors.response.use(
(response) => {
// Handle successful responses
return response;
},
(error) => {
// Handle errors globally
console.error('API Error:', error);
return Promise.reject(error);
}
);

Configuration Validation

Validate your configuration to catch issues early:

import { validateConfig } from '@devcogent/sdk';

const config = {
apiKey: process.env.DEVCOGENT_API_KEY,
environment: process.env.NODE_ENV
};

// Throws error if configuration is invalid
validateConfig(config);

const client = new Devcogent(config);

Framework-Specific Configuration

Next.js

// next.config.js
module.exports = {
env: {
DEVCOGENT_API_KEY: process.env.DEVCOGENT_API_KEY,
},
publicRuntimeConfig: {
devcogent: {
environment: process.env.NODE_ENV
}
}
};

Express.js

// app.js
const express = require('express');
const { Devcogent } = require('@devcogent/sdk');

const app = express();

// Initialize Devcogent middleware
app.use('/api', (req, res, next) => {
req.devcogent = new Devcogent({
apiKey: process.env.DEVCOGENT_API_KEY
});
next();
});

Best Practices

  1. Use environment variables for sensitive configuration
  2. Validate configuration before initializing the client
  3. Set appropriate timeouts for your use case
  4. Configure logging for debugging and monitoring
  5. Use different configurations for different environments

Troubleshooting

Common configuration issues:

  • Invalid API Key: Check that your API key is correct and active
  • Network Timeouts: Increase timeout values for slower networks
  • Rate Limiting: Adjust rate limit settings based on your plan
  • Environment Mismatch: Ensure you're using the correct environment settings

Next Steps