any-llm-ts
Operations

Responses API

Access compatible provider Responses endpoints without losing provider-specific fields.

Use responses() for providers that expose an OpenAI-compatible Responses API.

import { responses } from "any-llm-ts";

const response = await responses({
  provider: "openai",
  model: "gpt-4.1-mini",
  input: "Explain event loops in one paragraph.",
  timeout: 30,
});

timeout is expressed in seconds. Function tools may use either the native Responses shape or the chat-completions { type: "function", function: ... } shape; the latter is flattened before the request is sent.

The reusable client exposes the same operation:

const response = await llm.responses({
  model: "gpt-4.1-mini",
  input: [
    {
      role: "user",
      content: [{ type: "input_text", text: "Hello" }],
    },
  ],
});

The common surface uses OpenAI's exported Responses types, including Response and ResponseStreamEvent. Fields not modeled by the common parameters can still be passed through providerOptions:

const response = await llm.responses({
  ...params,
  providerOptions: { provider_specific_field: true },
});

console.log(response.output_text);

Streaming

const events = await llm.responses({
  model: "gpt-4.1-mini",
  input: "Hello",
  stream: true,
});

for await (const event of events) {
  // Validate and handle provider response events.
}

Gemini advertises Responses for a text-only Interactions subset. Vertex AI does not. Check metadata.capabilities.responses first. Unsupported providers reject with UnsupportedOperationError.

On this page