Installation and Setup
The ABV client library comes as a single npm package that includes everything you need. Install it in your project with npm, yarn, or pnpm:Client Initialization Patterns
The way you initialize the ABV client affects how you use it throughout your application. Let’s explore different patterns and when to use each. The simplest initialization creates a client with your API key directly:Client Lifecycle and Reuse
Creating an ABV client is lightweight, but you should generally create one client instance and reuse it throughout your application. The client maintains connection pooling and handles request optimization internally. For a Node.js server application, create the client once at startup and export it for use across your application:Working with Types
TypeScript’s type system helps catch errors before runtime. The ABV client library provides comprehensive type definitions that make working with the gateway safer and more productive. Import types from the client package to annotate your code:Handling Streaming Responses
Streaming responses arrive as an asynchronous iterable, which you consume using a for-await-of loop. This pattern feels natural in modern JavaScript and TypeScript:Error Handling Strategies
Gateway requests can fail for various reasons, and handling these failures gracefully improves your application’s reliability. TypeScript’s type system helps you handle errors correctly. The most basic error handling uses try-catch:Building Conversation Context
Most AI applications involve multi-turn conversations where the model needs context from previous exchanges. Managing this context is a core part of implementing chat applications. The straightforward approach maintains an array of messages that grows with the conversation:Implementing Function Calling
Function calling lets models invoke functions you define, enabling structured outputs and tool use. While the gateway supports function calling, the implementation details vary by provider. This example shows the general pattern:Framework Integration
The gateway integrates naturally with popular TypeScript frameworks. Here are patterns for common frameworks. For Express.js applications, add an endpoint that handles AI requests:Testing Strategies
Testing code that calls AI models requires different strategies than testing deterministic functions. You can’t assert exact outputs since model responses vary, but you can test the structure of your code and ensure error handling works correctly. Mock the ABV client for unit tests to avoid making actual API calls:Next Steps
You now understand how to implement the gateway in TypeScript applications, handle errors, manage conversations, and integrate with frameworks. Here’s where to go next:Python Guide
Learn how to implement the gateway in Python applications
Available Models
See all supported providers and models with pricing
LLM Gateway Overview
Understand the core concepts and architecture of the gateway
Quickstart
Get up and running with your first gateway request in 5 minutes