
Company News
AWS Security Hub Adds Socket for Supply Chain Security
Socket is now in the AWS Security Hub Extended plan. Adopt it through AWS, apply committed spend, and block malicious open source packages.
@sapiom/core
Advanced tools
⚠️ Beta Status: Currently in v0.x. API may change before v1.0.0. Production-ready and actively maintained.
Core SDK for Sapiom API providing HTTP client adapters, transaction management, and automatic payment handling.
npm install @sapiom/core
# or
pnpm add @sapiom/core
# or
yarn add @sapiom/core
import { SapiomClient } from '@sapiom/core';
const client = new SapiomClient({
apiKey: process.env.SAPIOM_API_KEY,
baseURL: 'https://api.sapiom.ai' // optional
});
// Create a transaction
const transaction = await client.transactions.create({
service: 'api',
action: 'call',
resource: 'completion',
qualifiers: {
model: 'gpt-4',
tokens: 1000
}
});
// Check transaction status
console.log(client.transactions.isAuthorized(transaction)); // boolean
For Axios integration, install the separate package:
npm install @sapiom/axios axios
import axios from 'axios';
import { withSapiom } from '@sapiom/axios';
const client = withSapiom(axios.create({
baseURL: 'https://api.example.com'
}), {
apiKey: process.env.SAPIOM_API_KEY
});
// Automatically handles 402 payment flows
const response = await client.get('/premium-endpoint');
See @sapiom/axios for complete documentation.
For Fetch API integration, install the separate package:
npm install @sapiom/fetch
import { createFetch } from '@sapiom/fetch';
const safeFetch = createFetch({
apiKey: process.env.SAPIOM_API_KEY
});
// Drop-in replacement for native fetch
const response = await safeFetch('https://api.example.com/data');
See @sapiom/fetch for complete documentation.
For Node.js HTTP/HTTPS integration, install the separate package:
npm install @sapiom/node-http
import { createClient } from '@sapiom/node-http';
const client = createClient({
apiKey: process.env.SAPIOM_API_KEY
});
const response = await client.request({
method: 'GET',
url: 'https://api.example.com/data'
});
See @sapiom/node-http for complete documentation.
new SapiomClient(config: SapiomClientConfig)
Config options:
apiKey: string - Required: Your Sapiom API keybaseURL?: string - Optional: API base URL (default: https://api.sapiom.ai)timeout?: number - Optional: Request timeout in ms (default: 30000)headers?: Record<string, string> - Optional: Additional headersawait client.transactions.create({
service: string;
action: string;
resource: string;
qualifiers?: Record<string, any>;
paymentData?: PaymentData;
metadata?: Record<string, any>;
})
await client.transactions.get(transactionId: string)
client.transactions.isAuthorized(transaction): boolean
client.transactions.isCompleted(transaction): boolean
client.transactions.requiresPayment(transaction): boolean
client.transactions.getPaymentDetails(transaction): PaymentDetails | null
All HTTP integrations accept a config object:
{
sapiom: {
apiKey: string;
baseURL?: string;
timeout?: number;
},
authorization?: {
enabled?: boolean;
authorizedEndpoints?: Array<{
pathPattern: RegExp;
service: string;
}>;
onAuthorizationPending?: (txId: string, endpoint: string) => void;
},
payment?: {
enabled?: boolean;
onPaymentRequired?: (txId: string, payment: PaymentDetails) => void;
}
}
All integrations automatically read from environment:
SAPIOM_API_KEY (required)SAPIOM_BASE_URL or SAPIOM_API_URL (optional)SAPIOM_TIMEOUT (optional, in milliseconds)try {
const transaction = await client.transactions.create({...});
} catch (error) {
if (error.response?.status === 401) {
console.error('Authentication failed');
} else if (error.response?.status === 402) {
console.error('Payment required');
} else if (error.response?.status === 403) {
console.error('Access denied');
}
}
import type { HttpClientAdapter, HttpRequest, HttpResponse } from '@sapiom/core';
class MyCustomAdapter implements HttpClientAdapter {
async request(config: HttpRequest): Promise<HttpResponse> {
// Your custom HTTP logic
}
}
import { isPaymentRequiredError, extractX402Response } from '@sapiom/core';
if (isPaymentRequiredError(error)) {
const x402Response = extractX402Response(error);
console.log('Payment required:', x402Response);
}
import type {
SapiomClientConfig,
TransactionResponse,
HttpClientAdapter,
HttpRequest,
HttpResponse,
X402Response,
X402PaymentRequirement,
} from '@sapiom/core';
MIT © Sapiom
FAQs
Core SDK for Sapiom API - Transaction management and core utilities
The npm package @sapiom/core receives a total of 9,485 weekly downloads. As such, @sapiom/core popularity was classified as popular.
We found that @sapiom/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket is now in the AWS Security Hub Extended plan. Adopt it through AWS, apply committed spend, and block malicious open source packages.

Research
/Security News
Popular npm packages keyv and cacheable compromised.

Security News
A misconfiguration gave three Anthropic models internet access, and one, believing it was in a simulation, shipped a credential-stealing package to PyPI.