Welcome to the Toolhouse TypeScript SDK documentation. This guide will help you get started with integrating and using the SDK in your project.
You can find example code for the following, natively-supported providers below:
- Anthropic Example
- OpenAI Example
- Vercel AI Example
The Toolhouse API provides access to various AI-powered tools and services, that you can find on Toolhouse.
This SDK is compatible with TypeScript >= 4.8.4
.
To get started with the SDK, we recommend installing it using npm
or yarn
:
npm install @toolhouseai/sdk
or
yarn add @toolhouseai/sdk
The Toolhouse API uses an Access Token for authentication. This token must be provided to authenticate your requests to the API.
To obtain an API Key, register at Toolhouse.
When initializing the SDK, set the access token as follows:
const toolhouse = new Toolhouse({
apiKey: process.env['TOOLHOUSE_API_KEY']
});
The apiKey
is the only mandatory parameter and represents the API key required to authenticate with the tool provider.
You can find working examples in the examples folder for JavaScript and examples folder for Typescript.
In addition to the apiKey
, you can configure the following options:
provider
: Specifies the provider, such as 'openai', 'anthropic', or 'vercel'. Defaults to 'openai'.baseUrl
: Optionally specify the base URL for API requests.timeoutMs
: The timeout for API requests, in milliseconds.metadata
: Additional metadata to include with requests.
Example:
const toolhouse = new Toolhouse({
apiKey: process.env['TOOLHOUSE_API_KEY'],
provider: 'anthropic',
timeoutMs: 10000,
metadata: { customField: 'value' }
});
Here's a basic example demonstrating how to authenticate and retrieve available tools:
import { Toolhouse } from '@toolhouseai/sdk';
import * as dotenv from 'dotenv';
dotenv.config();
async function main() {
const toolhouse = new Toolhouse({
apiKey: process.env['TOOLHOUSE_API_KEY']
});
const tools = await toolhouse.tools();
console.log(tools);
}
main();
Retrieves a list of public tools available from Toolhouse.
const tools = await toolhouse.tools();
console.log(tools);
Fetches tools from a specific provider (OpenAI, Anthropic, or Vercel).
const tools = await toolhouse.getTools('default');
console.log(tools);
Executes tools based on the provider and provided content.
const tools = await toolhouse.getTools();
const chatCompletion = await client.chat.completions.create({
messages,
model: 'gpt-3.5-turbo',
tools
});
const openAiMessage = await toolhouse.runTools(chatCompletion);
console.log(openAiMessage);
Retrieve or set the metadata used in tool requests.
console.log(toolhouse.metadata);
toolhouse.metadata = { newKey: 'newValue' };
Retrieve or set the provider for tool requests.
console.log(toolhouse.provider);
toolhouse.provider = 'anthropic';
Wrap API calls in try-catch blocks to handle potential errors:
try {
const tools = await toolhouse.tools();
} catch (error) {
console.error(error);
}
This SDK is licensed under the Apache-2.0 License. See the LICENSE file for more details.