Environment Setup: SDK, Auth, Dev Environment

AI Navigate Original / 5/16/2026

共有:

Key Points

  • Set up a minimal LLM-API environment for Node.js/Python
  • Install runtime, create project, .env + dotenv, first code
  • Pass keys via env vars; abstract providers with Vercel AI SDK
  • Use debug tools; know 401/429/400/500 common errors

Setting Up the Dev Environment

Here are the steps to set up a minimal environment for using LLM APIs, for Node.js / Python each.

Node.js Environment

1. Install Node.js

  • LTS version (v24+ recommended) from nodejs.org
  • Or version-manage with nvm / volta / fnm

2. Create a Project

mkdir my-ai-app && cd my-ai-app
npm init -y
npm install @anthropic-ai/sdk openai @google/genai
npm install -D typescript tsx @types/node
npx tsc --init

3. .env and dotenv

npm install dotenv

# .env
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GOOGLE_API_KEY=AIza...

4. First Code (TypeScript)

// index.ts
import "dotenv/config";
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();
const msg = await client.messages.create({
  model: "claude-opus-4-7",
  max_tokens: 256,
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(msg.content[0].text);

// Run
npx tsx index.ts

Python Environment

1. Install Python

  • Python 3.10+
  • Virtual env recommended: python -m venv .venv && source .venv/bin/activate

2. Packages

pip install anthropic openai google-generativeai python-dotenv

3. First Code

# main.py
from dotenv import load_dotenv
from anthropic import Anthropic

load_dotenv()
client = Anthropic()

msg = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=256,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(msg.content[0].text)

# Run
python main.py

Editor / IDE

  • VS Code + Cursor: powerful AI completion
  • Claude Code: terminal-CLI-centric development
  • Jupyter Notebook: handy for trial and error in Python

How to Pass the API Key

Method 1: Environment Variables (Recommended)

// Auto-loaded from .env (when using dotenv)
const client = new Anthropic();
// Reads process.env.ANTHROPIC_API_KEY internally

Method 2: Pass Explicitly

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

Multi-Provider Abstraction

Using the Vercel AI SDK makes switching vendors easy:

npm install ai @ai-sdk/openai @ai-sdk/anthropic @ai-sdk/google

// Same interface
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { anthropic } from "@ai-sdk/anthropic";

const { text } = await generateText({
  model: anthropic("claude-opus-4-7"),
  prompt: "Hello!",
});

Debug Tools

  • Postman / Insomnia: try the API instead of curl
  • LangSmith: trace LLM calls
  • Helicone: proxy-type logging
  • OpenAI Playground: try in a UI

Common Errors

  • 401 Unauthorized: wrong API key, or env var not loaded
  • 429 Rate Limit: too many calls, retry with exponential backoff
  • 400 Bad Request: prompt too long, or missing required param
  • 500 Server Error: API-side outage, retry later

Next Step

Once set up, implement chat/streaming in "Your First API Call."