Gateway

Quickstart

Make your first Hull Gateway request with the Vercel AI SDK, the OpenAI SDK or cURL.

This guide gets you from zero to a streamed response from Hull Gateway in a few minutes.

Before you start

Vercel AI SDK

Create a project

mkdir my-ai-app
cd my-ai-app
npm init -y
npm install ai @ai-sdk/openai dotenv

Add your API key

Create a .env file:

HULL_API_KEY=your_api_key_here

Write and run a script

Create index.mjs:

import { streamText } from "ai"
import { createOpenAI } from "@ai-sdk/openai"
import "dotenv/config"

const hull = createOpenAI({
  baseURL: "https://api.withhull.com/api/gateway",
  apiKey: process.env.HULL_API_KEY,
})

const result = streamText({
  model: hull.chat("anthropic/claude-sonnet-5"),
  prompt: "Invent a new holiday and describe its traditions.",
})

for await (const textPart of result.textStream) {
  process.stdout.write(textPart)
}

console.log()
console.log("Token usage:", await result.usage)
node index.mjs

The response streams to your terminal.

OpenAI SDK

Hull Gateway accepts OpenAI Chat Completions requests, so the OpenAI SDK works by changing the base URL.

import OpenAI from "openai"

const client = new OpenAI({
  apiKey: process.env.HULL_API_KEY,
  baseURL: "https://api.withhull.com/api/gateway",
})

const response = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-5",
  messages: [{ role: "user", content: "Why is the sky blue?" }],
})

console.log(response.choices[0].message.content)

cURL

curl -X POST "https://api.withhull.com/api/gateway/chat/completions" \
  -H "Authorization: Bearer $HULL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5",
    "messages": [{"role": "user", "content": "Why is the sky blue?"}]
  }'

Next steps

On this page