Skip to main content
The @output.ai/http package wraps ky with Output Framework tracing hooks for observable HTTP requests.

Installation

npm install @output.ai/http

Quick Start

import { httpClient } from '@output.ai/http';

const client = httpClient({
  prefixUrl: 'https://api.example.com'
});

const response = await client.get('users/1');
const data = await response.json();

Creating a Client

Configure a client with a base URL and default options:
import { httpClient } from '@output.ai/http';

const api = httpClient({
  prefixUrl: 'https://api.example.com',
  headers: {
    'Authorization': `Bearer ${process.env.API_TOKEN}`
  }
});

HTTP Methods

GET

const response = await client.get('users');
const users = await response.json();

POST

const response = await client.post('users', {
  json: {
    name: 'John Doe',
    email: 'john@example.com'
  }
});
const newUser = await response.json();

PUT

const response = await client.put('users/1', {
  json: {
    name: 'Jane Doe'
  }
});

DELETE

await client.delete('users/1');

Using in Steps

Wrap HTTP calls in steps for automatic retry and tracing:
steps.ts
import { step, z } from '@output.ai/core';
import { httpClient } from '@output.ai/http';

const api = httpClient({
  prefixUrl: 'https://api.example.com'
});

export const fetchUser = step({
  name: 'fetchUser',
  inputSchema: z.string(),
  outputSchema: z.object({
    id: z.string(),
    name: z.string(),
    email: z.string()
  }),
  fn: async (userId) => {
    const response = await api.get(`users/${userId}`);
    return response.json();
  }
});

Environment Variables

VariableDescription
LOG_HTTP_VERBOSESet to true for detailed request/response logging

Tracing

All HTTP requests made with @output.ai/http are automatically traced and visible in the Temporal UI, including:
  • Request URL and method
  • Request/response headers
  • Response status and timing
  • Error details on failure