> ## Documentation Index
> Fetch the complete documentation index at: https://www.adaline.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gateway

# Gateway Class

The main class for interacting with LLMs through the Adaline Gateway.

## Constructor

```typescript theme={null}
import { Gateway } from "@adaline/gateway";

const gateway = new Gateway({
  cache: myCache,        // optional: pluggable cache backend
  httpClient: myClient,  // optional: custom HTTP client
  logger: myLogger,      // optional: custom logger
});
```

### Parameters

**options** `GatewayOptionsType`

Optional configuration for plugins.

**GatewayOptionsType**

**cache** `Cache\<T\>`

A pluggable cache backend implementing the `Cache` interface.

**httpClient** `HttpClient`

A custom HTTP client implementing the `HttpClient` interface.

**logger** `Logger`

A custom logger implementing the `Logger` interface.

## Methods

### completeChat

Non-streaming chat completion. Sends messages to an LLM and returns the full response.

```typescript theme={null}
const response = await gateway.completeChat({
  model: gpt4o,
  config: Config().parse({ temperature: 0.7, maxTokens: 500 }),
  messages: [
    { role: "system", content: [{ modality: "text", value: "You are a helpful assistant." }] },
    { role: "user", content: [{ modality: "text", value: "Explain quantum computing." }] },
  ],
  tools: [],
});
```

**request** `GatewayCompleteChatRequestType` *required*

**Properties**

**model** `ChatModel` *required*

The model instance from a provider (e.g., `openai.chatModel({ modelName: "gpt-4o" })`).

**config** `Config` *required*

Model configuration parsed via `Config().parse({...})`. See [Config Type](https://www.adaline.ai/docs/reference/gateway/v2/types/config.md).

**messages** `MessageType[]` *required*

Array of messages. See [Message Types](https://www.adaline.ai/docs/reference/gateway/v2/types/messages.md).

**tools** `ToolType[]` *required*

Array of tool definitions (can be empty). See [Tool Types](https://www.adaline.ai/docs/reference/gateway/v2/types/tools.md).

**Returns:** `CompleteChatHandlerResponseType`

***

### streamChat

Streaming chat completion. Returns an async generator that yields response chunks.

```typescript theme={null}
for await (const chunk of gateway.streamChat({
  model: gpt4o,
  config: Config().parse({ temperature: 0.7, maxTokens: 500 }),
  messages: [
    { role: "user", content: [{ modality: "text", value: "Write a poem." }] },
  ],
  tools: [],
})) {
  process.stdout.write(chunk.response);
}
```

**request** `GatewayStreamChatRequestType` *required*

Same shape as `completeChat` request. See above.

**Returns:** `AsyncGenerator<StreamChatHandlerResponseType>`

***

### getEmbeddings

Generate embeddings for text or other modalities.

```typescript theme={null}
const embeddings = await gateway.getEmbeddings({
  model: textEmbedding3Large,
  config: Config().parse({ encodingFormat: "float", dimensions: 256 }),
  embeddingRequests: {
    modality: "text",
    requests: ["Hello world", "How are you?"],
  },
});
```

**request** `GatewayGetEmbeddingsRequestType` *required*

**Properties**

**model** `EmbeddingModel` *required*

The embedding model instance from a provider.

**config** `Config` *required*

Embedding model configuration.

**embeddingRequests** `EmbeddingRequestType` *required*

The input data to embed.

**Returns:** `GetEmbeddingsHandlerResponseType`

***

### getToolResponses

Execute tool calls returned by an LLM.

```typescript theme={null}
const toolResponses = await gateway.getToolResponses({
  tools: myToolDefinitions,
  toolCalls: response.toolCalls,
});
```

**request** `GatewayGetToolResponsesRequestType` *required*

**Properties**

**tools** `ToolType[]` *required*

The tool definitions that match the tool calls.

**toolCalls** `ToolCallType[]` *required*

Tool calls returned from a chat completion response.

**Returns:** `GetToolResponsesHandlerResponseType`

***

### getChatUsageCost (static)

Calculate the cost of a chat completion based on token usage.

```typescript theme={null}
const cost = Gateway.getChatUsageCost({
  model: gpt4o,
  usage: response.usage,
});
```

**Returns:** `GetChatUsageCostHandlerResponseType`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.