The Axion SDK uses API key authentication to secure access to financial data endpoints. This guide covers how to obtain, configure, and manage your API keys.
The SDK automatically determines whether authentication is required for each endpoint:
Copy
Ask AI
// These endpoints require an API keyconst stock = await client.stocks.ticker('AAPL');const prices = await client.stocks.prices('AAPL');const sentiment = await client.sentiment.all('AAPL');const financials = await client.financials.metrics('AAPL');
Most endpoints require authentication. When an API key is required but not provided, the SDK throws an error: "Authentication required but no API key provided to client."
The SDK provides clear error messages for authentication issues:
Copy
Ask AI
import { Axion } from '@axionquant/sdk';const client = new Axion(); // No API keytry { const stock = await client.stocks.ticker('AAPL');} catch (error) { if (error.message.includes('Authentication required')) { console.error('Please provide an API key'); console.error('Initialize with: new Axion("your-api-key")'); }}
Authentication required but no API key provided to client
error
Cause: Trying to access an authenticated endpoint without providing an API key.Solution: Initialize the client with your API key: new Axion('your-api-key')
The SDK automatically manages the Authorization header, but you can access the underlying axios client for advanced configuration:
Copy
Ask AI
import { Axion } from '@axionquant/sdk';const client = new Axion('your-api-key');// The Authorization header is automatically set to:// Authorization: Bearer your-api-key
You can create multiple client instances with different API keys:
Copy
Ask AI
const clientProd = new Axion(process.env.AXION_API_KEY_PROD);const clientDev = new Axion(process.env.AXION_API_KEY_DEV);// Use different clients for different purposesconst prodData = await clientProd.stocks.ticker('AAPL');const devData = await clientDev.stocks.ticker('TEST');
For development and testing with a local server that doesn’t require authentication:
Copy
Ask AI
// Initialize without an API keyconst client = new Axion();// Only works if your test server doesn't require authtry { const data = await client.stocks.ticker('AAPL'); console.log('Test data:', data);} catch (error) { if (error.message.includes('Authentication required')) { console.log('This endpoint requires authentication'); }}
This approach only works with endpoints that explicitly don’t require authentication or when testing against a local development server.