In this guide you'll learn how to implement and use Toolhouse with just a few lines of code. For the purpose of this example, we'll build an assistant that can get the contents of a page and summarize it for us. We'll do so by using the Get page contents tool.
Sign up
You can sign up for free by going to the Toolhouse sign up page. You can skip this step if you already signed up for Toolhouse.
Create an API Key
You will need to generate an API Key in order to use Toolhouse with your code.
You'll find a field that says API Key Name. Give your API Key a name, then click Generate
Copy the API Key and save it where you save your secrets.
In this guide, we'll assume you have a .env file. Save the API Key as TOOLHOUSE_API_KEY in your environment file. This allows Toolhouse to pick up its value directly in your code.
TOOLHOUSE_API_KEY=<Your API Key value>
Add a tool
In Toolhouse, tools are function definitions. In Toolhouse, tools can be local (meaning they run on your infrastructure, such as your cloud environment or just your laptop) or cloud (meaning they are executed in the Toolhouse Cloud).
All the tools on Toolhouse are pre-installed on your account!
You can either call all tools by default as they come pre-installed in your account, or create Bundles to add tools. To add tools to a bundle, follow these steps:
Click on the "Create Bundle" button at the top right corner of the screen.
Give your bundle a name and select all the tools you'd want to add.
To follow along, add the Get page contents tool.
That's it! You just enabled a fully sandboxed scraper that can work on any LLM you wish to use.
Add Toolhouse to your code
Import the Toolhouse SDK in your project:
npm i @toolhouseai/sdk
yarn add @toolhouseai/sdk
Then, simply instantiate the SDK and pass the tool definitions in your LLM call. Toolhouse will encapsulate the logic you usually need to pass the tool output back to the LLM, so you won't have to worry about writing boilerplate logic.
import { Toolhouse } from"@toolhouseai/sdk";// 👋 Remember to install the OpenAI SDK! npm i openaiimport OpenAI from"openai";constMODEL="gpt-4o-mini";asyncfunctionmain() {consttoolhouse=newToolhouse({ apiKey:process.env.TOOLHOUSE_API_KEY, metadata: {"id":"daniele","timezone":"0" } });constclient=newOpenAI({ apiKey:process.env.OPENAI_API_KEY });constmessages:OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [{"role":"user","content":"Get the contents of https://toolhouse.ai and summarize them in a few bullet points.", }];consttools=awaittoolhouse.getTools() asOpenAI.Chat.Completions.ChatCompletionTool[];constchatCompletion=awaitclient.chat.completions.create({ messages, model:MODEL, tools })constopenAiMessage=awaittoolhouse.runTools(chatCompletion) asOpenAI.Chat.Completions.ChatCompletionMessageParam[]constnewMessages= [...messages,...openAiMessage]constchatCompleted=awaitclient.chat.completions.create({ messages: newMessages, model:MODEL, tools })console.log(JSON.stringify(chatCompleted))}main();
// 👋 Remember to install the Anthropic SDK! npm i @anthropic-ai/sdkimport Anthropic from"@anthropic-ai/sdk";import { Toolhouse } from"@toolhouseai/sdk";asyncfunctionmain() {constclient=newAnthropic({ apiKey:process.env.ANTHROPIC_API_KEY, })consttoolhouse=newToolhouse({ apiKey:process.env.TOOLHOUSE_API_KEY, provider:"anthropic", metadata: {"id":"daniele","timezone":"0" } });constmessages:Anthropic.Messages.MessageParam[] = [{"role":"user","content":"Get the contents of https://toolhouse.ai and summarize them in a few bullet points.", }];consttools=awaittoolhouse.getTools() asAnthropic.Messages.Tool[]constmessage=awaitclient.messages.create({ max_tokens:1024, messages, model:"claude-3-5-sonnet-latest", tools })constanthropicMessage=awaittoolhouse.runTools(message) asAnthropic.Messages.MessageParam[]constnewMessages= [...messages,...anthropicMessage]constchatCompleted=awaitclient.messages.create({ max_tokens:1024, messages: newMessages, model:"claude-3-5-sonnet-latest", tools })console.log(JSON.stringify(chatCompleted))}main()
import { Toolhouse } from'@toolhouseai/sdk';// 👋 In this example we use the OpenAI SDK which is compatible with Groq.// You can also install the native Groq SDK if you prefer.// Remember to install the one you prefer: npm i openai or npm i groq-sdkimport OpenAI from'openai';constMODEL='gpt-4o-mini';asyncfunctionmain() {consttoolhouse=newToolhouse({ apiKey:process.env.TOOLHOUSE_API_KEY, metadata: {"id":"daniele","timezone":"0" } });constclient=newOpenAI({ baseURL:"https://api.groq.com/openai/v1", apiKey:process.env.GROQ_API_KEY, });constmessages:OpenAI.Chat.Completions.ChatCompletionMessageParam[] = [{"role":"user","content":"Get the contents of https://toolhouse.ai and summarize them in a few bullet points.", }];consttools=awaittoolhouse.getTools() asOpenAI.Chat.Completions.ChatCompletionTool[];constchatCompletion=awaitclient.chat.completions.create({ messages, model:MODEL, tools })constopenAiMessage=awaittoolhouse.runTools(chatCompletion) asOpenAI.Chat.Completions.ChatCompletionMessageParam[]constnewMessages= [...messages,...openAiMessage]constchatCompleted=awaitclient.chat.completions.create({ messages: newMessages, model:MODEL, tools })console.log(JSON.stringify(chatCompleted))}main();