TypeScript Client Guide
@datafuse/sdk is a typed client generated from the Datafuse API. Each method maps to one v1 route. It uses the built-in fetch, has no runtime dependencies, and works from both ES modules and CommonJS.
npm install @datafuse/sdk
The examples use top-level await: save them as an ES module, for example tools.mjs.
1. Create a Client
Pass the credential yourself: the SDK does not read environment variables. The client sends it as both Authorization: Bearer and x-api-key, so one client works with either credential type.
import { Datafuse } from '@datafuse/sdk'
const sdk = new Datafuse({ apiKey: process.env.DATAFUSE_API_KEY })
You pass as apiKey | The client can |
|---|---|
An API key (df_live_...) | Resolve tools, list tools, export tool schemas, invoke tools, list connected accounts, browse providers |
| An access token | Everything above except connected accounts, plus list, create, test and delete integrations |
For a self-hosted deployment add baseUrl: 'https://your-datafuse-host'.
2. Find a Verified Integration
Listing integrations needs an access token. Do this once and keep the id.
const admin = new Datafuse({ apiKey: process.env.DF_TOKEN })
const page = await admin.integrations.listIntegrationsApiV1IntegrationsGet()
const integration = page.items.find((item) => item.verified)
if (!integration) throw new Error('No verified integration. Connect and verify one in the dashboard first.')
const integrationId = integration.id
console.log(integration.provider_key, integrationId)
To check an integration's credentials from code, call admin.integrations.testIntegrationApiV1IntegrationsIdTestPost({ id }) and read verified on the result.
3. Resolve Tools
const tools = await sdk.integrations.resolveToolsApiV1IntegrationsIdResolveToolsPost({ id: integrationId })
for (const tool of tools) {
console.log(tool.slug, tool.input_schema?.required ?? [])
}
4. Invoke a Tool
Pass a tool's slug as tool_key. This example calls DeepSeek's read-only deepseek_list_models; use a slug and arguments from your own integration.
const result = await sdk.integrations.invokeToolApiV1IntegrationsIdInvokePost({
id: integrationId,
integrationInvokeRequest: { tool_key: 'deepseek_list_models', arguments: {} }
})
console.log(result.successful)
console.log(result.successful ? result.data : result.error)
Errors
A non-2xx response rejects with a ResponseError that carries the original Response:
try {
await sdk.integrations.resolveToolsApiV1IntegrationsIdResolveToolsPost({ id: integrationId })
} catch (error) {
if (error.response) console.error(error.response.status, await error.response.text())
else throw error
}
401 means the credential is not accepted on that route. 403 with connection_verification_required means the integration's credentials are not verified.
Client Layout
| Property | Routes |
|---|---|
sdk.integrations | Integrations, tool resolution, tool schemas, invoke |
sdk.providers | Provider catalog |
sdk.connectedAccounts | Connected accounts |
sdk.apiKeys, sdk.auth | API keys, login and refresh |
sdk.organizations, sdk.billing, sdk.auditLogs | Account, billing and audit |
Method names follow the route they call. Use your editor's completion on each property to browse them.
Next Steps
- See which credential each route accepts in the Client Overview.
- Open the Python client guide for Python services.