> ## 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

<ParamField body="options" type="GatewayOptionsType" optional>
  Optional configuration for plugins.

  <Expandable title="GatewayOptionsType">
    <ParamField body="cache" type="Cache<T>" optional>
      A pluggable cache backend implementing the `Cache` interface.
    </ParamField>

    <ParamField body="httpClient" type="HttpClient" optional>
      A custom HTTP client implementing the `HttpClient` interface.
    </ParamField>

    <ParamField body="logger" type="Logger" optional>
      A custom logger implementing the `Logger` interface.
    </ParamField>
  </Expandable>
</ParamField>

## 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: [],
});
```

<ParamField body="request" type="GatewayCompleteChatRequestType" required>
  <Expandable title="Properties">
    <ParamField body="model" type="ChatModel" required>
      The model instance from a provider (e.g., `openai.chatModel({ modelName: "gpt-4o" })`).
    </ParamField>

    <ParamField body="config" type="Config" required>
      Model configuration parsed via `Config().parse({...})`. See [Config Type](/docs/reference/gateway/v2/types/config).
    </ParamField>

    <ParamField body="messages" type="MessageType[]" required>
      Array of messages. See [Message Types](/docs/reference/gateway/v2/types/messages).
    </ParamField>

    <ParamField body="tools" type="ToolType[]" required>
      Array of tool definitions (can be empty). See [Tool Types](/docs/reference/gateway/v2/types/tools).
    </ParamField>
  </Expandable>
</ParamField>

**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);
}
```

<ParamField body="request" type="GatewayStreamChatRequestType" required>
  Same shape as `completeChat` request. See above.
</ParamField>

**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?"],
  },
});
```

<ParamField body="request" type="GatewayGetEmbeddingsRequestType" required>
  <Expandable title="Properties">
    <ParamField body="model" type="EmbeddingModel" required>
      The embedding model instance from a provider.
    </ParamField>

    <ParamField body="config" type="Config" required>
      Embedding model configuration.
    </ParamField>

    <ParamField body="embeddingRequests" type="EmbeddingRequestType" required>
      The input data to embed.
    </ParamField>
  </Expandable>
</ParamField>

**Returns:** `GetEmbeddingsHandlerResponseType`

***

### getToolResponses

Execute tool calls returned by an LLM.

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

<ParamField body="request" type="GatewayGetToolResponsesRequestType" required>
  <Expandable title="Properties">
    <ParamField body="tools" type="ToolType[]" required>
      The tool definitions that match the tool calls.
    </ParamField>

    <ParamField body="toolCalls" type="ToolCallType[]" required>
      Tool calls returned from a chat completion response.
    </ParamField>
  </Expandable>
</ParamField>

**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`
