59API

← Back to all guides

Call Claude and GPT in TypeScript: A 59API Quick Start

Guides · EN · 2026-10-22

One Node.js client, two model families

If you want to test Claude and GPT without maintaining separate client integrations, an OpenAI-compatible relay can simplify your setup. This quick start uses TypeScript and the official OpenAI JavaScript SDK to send requests through 59API.

59API provides low-cost, pay-as-you-go access to Claude and GPT models through https://api.59api.com. It describes its service as using native, official-quality models without downgrading, and positions itself among the cheapest relays. Compare current per-model prices before choosing: input tokens, output tokens, and caching rules can affect your actual bill.

1. Install the SDK and TypeScript runner

Use Node.js 22 or newer. Create a project directory, open a terminal there, and run these commands in order:

The tsx runner executes TypeScript directly, so you can test this integration without configuring a build pipeline. For a production application, add your normal type-checking and deployment steps afterward.

2. Configure credentials and model IDs

Create a 59API account, generate an API key, and copy two available model IDs from its dashboard or documentation: one Claude model and one GPT model. Use exact identifiers rather than assuming an upstream model name is available through the relay.

Create a file named .env with the following entries, each on its own line:

The service root is https://api.59api.com; this example uses the conventional OpenAI-compatible /v1 prefix. Confirm the current SDK base URL in 59API’s documentation and adjust API_BASE_URL if necessary. Do not append /chat/completions yourself: the SDK supplies that endpoint path.

Add .env to your .gitignore. Keep this key on your server, not inside browser code or a public repository.

3. Make both requests from TypeScript

Create quickstart.ts and paste this code. Both requests use the same client; only the model identifier changes.

import OpenAI from "openai"; const { API_KEY, API_BASE_URL, CLAUDE_MODEL, GPT_MODEL } = process.env; if (!API_KEY || !API_BASE_URL || !CLAUDE_MODEL || !GPT_MODEL) { throw new Error("Missing required environment variables"); } const client = new OpenAI({ apiKey: API_KEY, baseURL: API_BASE_URL, timeout: 30000, maxRetries: 2 }); async function ask(model: string) { const result = await client.chat.completions.create({ model, messages: [{ role: "user", content: "Explain an HTTP 429 response in two sentences." }] }); console.log(model, result.choices[0]?.message.content ?? "No text returned"); console.log("Usage:", result.usage); } async function main() { await ask(CLAUDE_MODEL!); await ask(GPT_MODEL!); } main().catch((error: unknown) => { if (error instanceof OpenAI.APIError) { console.error("API error:", error.status, error.message); } else { console.error(error); } process.exitCode = 1; });

Run it with node --env-file=.env --import tsx quickstart.ts. You should see two answers and any usage metadata the relay returns. Calls run sequentially here, making failures easier to isolate.

4. Check compatibility and control spending

5. Pick the economical default

Use a lower-cost model for routine extraction or classification, then evaluate stronger models for difficult reasoning. 59API’s referral rebate may further reduce effective spending, subject to its current terms. When you are ready, sign up for 59API and benchmark one small, representative workload before scaling up.

Pricing · Docs

Ready to get started?

Connect Claude & GPT in minutes at the lowest prices — full-power, never downgraded. Sign up to get your API key.

Sign up free