Langbase SDK
The AI SDK for building declarative and composable AI-powered LLM products.
Documentation
Check the Langbase SDK documentation for more details.
The following examples are for reference only. Prefer docs for the latest information.
Getting Started with langbase
SDK
Installation
First, install the langbase
package using npm or yarn:
npm install langbase
or
pnpm add langbase
or
yarn add langbase
Usage
You can generateText
or streamText
based on the type of a pipe.
Check our SDK documentation for more details.
Example projects
Check the following examples:
Node.js Example Code
Node.js Examples
Add a .env
file with your Pipe API key
LANGBASE_PIPE_API_KEY="pipe_12345`"
For more check the API reference of generateText()
import 'dotenv/config';
import {Pipe} from 'langbase';
const pipe = new Pipe({
apiKey: process.env.LANGBASE_PIPE_API_KEY!,
});
const result = await pipe.generateText({
messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
});
console.log(result.completion);
For more check the API reference of streamText()
import 'dotenv/config';
import {Pipe} from 'langbase';
const pipe = new Pipe({
apiKey: process.env.LANGBASE_PIPE_API_KEY!,
});
const stream = await pipe.streamText({
messages: [{role: 'user', content: 'Who is an AI Engineer?'}],
});
for await (const chunk of stream) {
const textPart = chunk.choices[0]?.delta?.content || '';
process.stdout.write(textPart);
}
Check out more examples in the docs →