Getting Started
This guide walks you through installing ThinkLang and running your first AI-powered program.
Prerequisites
- Node.js 18+ (LTS recommended)
- An Anthropic API key for AI features
Installation
Install ThinkLang globally from npm:
npm install -g thinklangOr run it directly without installing:
npx thinklang run hello.tlEnvironment Setup
Set your Anthropic API key as an environment variable:
export ANTHROPIC_API_KEY=sk-ant-your-key-hereYou can also create a .env file in your project directory:
ANTHROPIC_API_KEY=sk-ant-your-key-here
THINKLANG_MODEL=claude-opus-4-6
THINKLANG_CACHE=true| Variable | Required | Default | Description |
|---|---|---|---|
ANTHROPIC_API_KEY | Yes | -- | Your Anthropic API key |
THINKLANG_MODEL | No | claude-opus-4-6 | Model to use for AI calls |
THINKLANG_CACHE | No | true | Cache identical AI requests |
Your First Program
Create a file called hello.tl:
let greeting = think<string>("Say hello to the world in a creative way")
print greetingRun it:
thinklang run hello.tlThe think keyword calls an LLM and returns a typed result. Here we asked for a string, so that is exactly what we get back.
A Structured Example
ThinkLang shines when you define types for AI outputs. Create classify.tl:
type Classification {
@description("The category of the email")
category: string
@description("Confidence score from 0 to 1")
confidence: float
@description("Brief explanation")
reason: string
}
let email = "Congratulations! You've won a FREE iPhone! Click here now!"
let result = think<Classification>("Classify this email as spam, promotional, personal, or work")
with context: email
print resultThe AI returns a structured Classification object with exactly the fields you defined.
CLI Commands
| Command | Description |
|---|---|
thinklang run <file.tl> | Run a ThinkLang program |
thinklang compile <file.tl> | Emit compiled TypeScript to stdout |
thinklang repl | Start an interactive REPL session |
thinklang test [target] | Run .test.tl test files |
thinklang cost-report | Show cost summary for the current session |
Useful Flags
thinklang run --show-cost-- Print a cost summary after executionthinklang compile -o output.ts-- Write compiled output to a filethinklang test --replay-- Run tests using recorded snapshotsthinklang test --update-snapshots-- Record live responses to snapshot filesthinklang test --pattern <regex>-- Filter test files by pattern
Splitting Code Across Files
As your programs grow, use import to share types and functions between files:
// types.tl
type Sentiment {
label: string
score: float
}// main.tl
import { Sentiment } from "./types.tl"
let result = think<Sentiment>("Analyze sentiment of this review")
with context: review
print resultAll top-level type and fn declarations are automatically importable -- no export keyword is needed.
Next Steps
- Take the Language Tour for a quick overview of all features
- Learn about the Type System
- Explore AI Primitives:
think,infer, andreason