from line 4
44description: Make your first API call to Claude and build a simple web search assistant.
55---
66
7## Prerequisites
7## Before you begin
88
9* A [Claude Console account](https://platform.claude.com/)
10* An [API key](https://platform.claude.com/docs/en/get-api-key)
9<Steps continues>
10 <Step title="Create a Claude Console account">
11 [Sign up](https://platform.claude.com/) for a Claude Console account, or sign in to the one you have.
12 </Step>
1113
14 <Step title="Choose how to authenticate">
15 Signing in with the CLI is recommended for local development.
16
17 Follow the steps for one of the following options.
18 </Step>
19</Steps>
20
21**CLI**
22
23<Steps continued>
24 <Step title="Install the CLI" stepNumber={3}>
25 <Tabs noDeepLinks>
26 <Tab title="Homebrew (macOS)">
27 ```bash
28 brew install anthropics/tap/ant
29 ```
30 </Tab>
31
32 <Tab title="curl (Linux/WSL)">
33 For Linux environments, download the release binary directly.
34
35 ```bash
36 VERSION=2.5.0
37 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
38 case $(uname -m) in
39 x86_64) ARCH=amd64 ;;
40 aarch64) ARCH=arm64 ;;
41 esac
42 curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \
43 | sudo tar -xz -C /usr/local/bin ant
44 ```
45
46 You can find all releases on the [GitHub releases page](https://github.com/anthropics/anthropic-cli/releases).
47 </Tab>
48
49 <Tab title="go install">
50 You can also install the CLI from source using `go install`. Requires Go 1.25 or later.
51
52 ```bash
53 go install github.com/anthropics/anthropic-cli/v2/cmd/ant@latest
54 ```
55
56 The binary is placed in `$(go env GOPATH)/bin`. Add it to your `PATH` if it isn’t already:
57
58 ```bash
59 export PATH="$PATH:$(go env GOPATH)/bin"
60 ```
61 </Tab>
62 </Tabs>
63 </Step>
64
65 <Step title="Sign in" stepNumber={4}>
66 ```bash
67 ant auth login
68 ```
69
70 Once login is completed, the SDKs and CLI will pick up your credentials automatically.
71 </Step>
72</Steps>
73
74**API key**
75
76<Steps continued>
77 <Step title="Create an API key" stepNumber={3}>
78 Create an [API key](https://platform.claude.com/settings/keys) in the Claude Console.
79 </Step>
80
81 <Step title="Set the environment variable" stepNumber={4}>
82 The SDKs and CLI read your key from `ANTHROPIC_API_KEY`:
83
84 ```bash
85 export ANTHROPIC_API_KEY="your-api-key-here"
86 ```
87 </Step>
88</Steps>
89
1290## Call the API
1391
1492<Tabs>
1593 <Tab title="cURL">
1694 <Steps>
17 <Step title="Set your API key">
18 Export your API key as an environment variable. The cURL command in the following step reads it from `$ANTHROPIC_API_KEY`.
95 <Step title="Make your first API call" stepNumber={5}>
96 **CLI**
1997
20 ```bash
21 export ANTHROPIC_API_KEY="your-api-key-here"
98 Send a `POST` request to the Messages API, with [the access token from your CLI sign-in](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/scripting#authenticate-curl-requests-with-cli-credentials) as a bearer token:
99
100 ```bash cURL
101 curl https://api.anthropic.com/v1/messages \
102 -H "content-type: application/json" \
103 -H "Authorization: Bearer $(ant auth print-credentials --access-token)" \
104 -H "anthropic-version: 2026-10-21" \
105 -d '{
106 "model": "claude-opus-5-5",
107 "max_tokens": 1000,
108 "messages": [
109 {
110 "role": "user",
111 "content": "What should I search for to find the latest developments in renewable energy?"
112 }
113 ]
114 }'
22115 ```
23 </Step>
24116
25 <Step title="Make your first API call">
117 **API key**
118
26119 Send a `POST` request to the Messages API:
27120
28121 ```bash cURL
from line 164
71164
72165 <Tab title="CLI">
73166 <Steps>
74 <Step title="Install the CLI">
75 Install the Anthropic CLI with Homebrew:
167 <Step title="Make your first API call" stepNumber={5}>
168 **API key**
76169
77 ```bash
78 brew install anthropics/tap/ant
79 ```
170 If you chose API key earlier, install the CLI first:
80171
81 For other installation methods, see [Installation](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/quickstart#installation) in the CLI quickstart.
82 </Step>
172 <Tabs noDeepLinks>
173 <Tab title="Homebrew (macOS)">
174 ```bash
175 brew install anthropics/tap/ant
176 ```
177 </Tab>
83178
84 <Step title="Authenticate">
85 Log in with your Anthropic account:
179 <Tab title="curl (Linux/WSL)">
180 For Linux environments, download the release binary directly.
86181
87 ```bash
88 ant auth login
89 ```
182 ```bash
183 VERSION=2.5.0
184 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
185 case $(uname -m) in
186 x86_64) ARCH=amd64 ;;
187 aarch64) ARCH=arm64 ;;
188 esac
189 curl -fsSL "https://github.com/anthropics/anthropic-cli/releases/download/v${VERSION}/ant_${VERSION}_${OS}_${ARCH}.tar.gz" \
190 | sudo tar -xz -C /usr/local/bin ant
191 ```
90192
91 This opens a browser-based OAuth flow. After authorizing, confirm your credential with:
193 You can find all releases on the [GitHub releases page](https://github.com/anthropics/anthropic-cli/releases).
194 </Tab>
92195
93 ```bash
94 ant auth status
95 ```
196 <Tab title="go install">
197 You can also install the CLI from source using `go install`. Requires Go 1.25 or later.
96198
97 On a remote host without a browser, pass `--no-browser` to get a URL you can open on another device, then paste the returned code back into the terminal. For non-interactive environments such as CI, see [CLI authentication options](https://platform.claude.com/docs/en/cli-sdks-libraries/cli/authentication).
98 </Step>
199 ```bash
200 go install github.com/anthropics/anthropic-cli/v2/cmd/ant@latest
201 ```
99202
100 <Step title="Make your first API call">
203 The binary is placed in `$(go env GOPATH)/bin`. Add it to your `PATH` if it isn’t already:
204
205 ```bash
206 export PATH="$PATH:$(go env GOPATH)/bin"
207 ```
208 </Tab>
209 </Tabs>
210
101211 Run `ant messages create` from your terminal:
102212
103213 ```bash CLI
from line 246
136246
137247 <Tab title="Python">
138248 <Steps>
139 <Step title="Set your API key">
140 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
141
249 <Step title="Create a project and install the SDK" stepNumber={5}>
142250 ```bash
143 export ANTHROPIC_API_KEY="your-api-key-here"
144 ```
145 </Step>
146
147 <Step title="Create a project and install the SDK">
148 ```bash
149251 mkdir claude-quickstart && cd claude-quickstart
150252 python3 -m venv .venv && source .venv/bin/activate
151253 pip install anthropic
from line 254
152254 ```
153255 </Step>
154256
155 <Step title="Create your code">
257 <Step title="Create your code" stepNumber={6}>
156258 Create a file called `quickstart.py`:
157259
158260 ```python Python
from line 279
177279 ```
178280 </Step>
179281
180 <Step title="Run your code">
282 <Step title="Run your code" stepNumber={7}>
181283 ```bash
182284 python quickstart.py
183285 ```
from line 297
195297
196298 <Tab title="TypeScript">
197299 <Steps>
198 <Step title="Set your API key">
199 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
200
300 <Step title="Create a project and install the SDK" stepNumber={5}>
201301 ```bash
202 export ANTHROPIC_API_KEY="your-api-key-here"
203 ```
204 </Step>
205
206 <Step title="Create a project and install the SDK">
207 ```bash
208302 mkdir claude-quickstart && cd claude-quickstart
209303 npm init -y
210304 npm pkg set type=module
from line 306
212306 ```
213307 </Step>
214308
215 <Step title="Create your code">
309 <Step title="Create your code" stepNumber={6}>
216310 Create a file called `quickstart.ts`:
217311
218312 ```typescript TypeScript
from line 333
239333 ```
240334 </Step>
241335
242 <Step title="Run your code">
336 <Step title="Run your code" stepNumber={7}>
243337 ```bash
244338 npx tsx quickstart.ts
245339 ```
from line 351
257351
258352 <Tab title="C#">
259353 <Steps>
260 <Step title="Set your API key">
261 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
262
263 ```bash
264 export ANTHROPIC_API_KEY="your-api-key-here"
265 ```
266 </Step>
267
268 <Step title="Create a project and install the SDK">
354 <Step title="Create a project and install the SDK" stepNumber={5}>
269355 Create a new console project and add the Anthropic package:
270356
271357 ```bash
from line 361
275361 ```
276362 </Step>
277363
278 <Step title="Create your code">
364 <Step title="Create your code" stepNumber={6}>
279365 Replace the contents of `Program.cs`:
280366
281367 ```csharp C#
from line 393
307393 ```
308394 </Step>
309395
310 <Step title="Run your code">
396 <Step title="Run your code" stepNumber={7}>
311397 ```bash
312398 dotnet run
313399 ```
from line 411
325411
326412 <Tab title="Go">
327413 <Steps>
328 <Step title="Set your API key">
329 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
330
331 ```bash
332 export ANTHROPIC_API_KEY="your-api-key-here"
333 ```
334 </Step>
335
336 <Step title="Create a project and install the SDK">
414 <Step title="Create a project and install the SDK" stepNumber={5}>
337415 Create a new module and add the Anthropic SDK:
338416
339417 ```bash
from line 421
343421 ```
344422 </Step>
345423
346 <Step title="Create your code">
424 <Step title="Create your code" stepNumber={6}>
347425 Create a file called `main.go`:
348426
349427 ```go Go
from line 458
380458 ```
381459 </Step>
382460
383 <Step title="Run your code">
461 <Step title="Run your code" stepNumber={7}>
384462 ```bash
385463 go run .
386464 ```
from line 476
398476
399477 <Tab title="Java">
400478 <Steps>
401 <Step title="Set your API key">
402 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
403
404 ```bash
405 export ANTHROPIC_API_KEY="your-api-key-here"
406 ```
407 </Step>
408
409 <Step title="Set up your project">
479 <Step title="Set up your project" stepNumber={5}>
410480 You need a JDK (25 or later) and either [Gradle](https://gradle.org/install/) or [Maven](https://maven.apache.org/install.html) on your `PATH`. Create a directory for your project with a Java source directory inside it:
411481
412482 ```bash
from line 540
470540 </Tabs>
471541 </Step>
472542
473 <Step title="Create your code">
543 <Step title="Create your code" stepNumber={6}>
474544 Save this as `QuickStart.java` in your project’s Java source directory (usually `src/main/java/`):
475545
476546 ```java Java
from line 568
498568 ```
499569 </Step>
500570
501 <Step title="Run your code">
571 <Step title="Run your code" stepNumber={7}>
502572 <Tabs>
503573 <Tab title="Gradle">
504574 ```bash
from line 596
526596
527597 <Tab title="PHP">
528598 <Steps>
529 <Step title="Set your API key">
530 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
531
599 <Step title="Create a project and install the SDK" stepNumber={5}>
532600 ```bash
533 export ANTHROPIC_API_KEY="your-api-key-here"
534 ```
535 </Step>
536
537 <Step title="Create a project and install the SDK">
538 ```bash
539601 mkdir claude-quickstart && cd claude-quickstart
540602 composer require "anthropic-ai/sdk" "guzzlehttp/guzzle:^7"
541603 ```
542604 </Step>
543605
544 <Step title="Create your code">
606 <Step title="Create your code" stepNumber={6}>
545607 Create a file called `quickstart.php`:
546608
547609 ```php PHP
from line 635
573635 ```
574636 </Step>
575637
576 <Step title="Run your code">
638 <Step title="Run your code" stepNumber={7}>
577639 ```bash
578640 php quickstart.php
579641 ```
from line 653
591653
592654 <Tab title="Ruby">
593655 <Steps>
594 <Step title="Set your API key">
595 Export your API key as an environment variable. The SDK reads `ANTHROPIC_API_KEY` automatically.
596
656 <Step title="Create a project and install the SDK" stepNumber={5}>
597657 ```bash
598 export ANTHROPIC_API_KEY="your-api-key-here"
599 ```
600 </Step>
601
602 <Step title="Create a project and install the SDK">
603 ```bash
604658 mkdir claude-quickstart && cd claude-quickstart
605659 bundle init
606660 bundle add anthropic
from line 661
607661 ```
608662 </Step>
609663
610 <Step title="Create your code">
664 <Step title="Create your code" stepNumber={6}>
611665 Create a file called `quickstart.rb`:
612666
613667 ```ruby Ruby
from line 686
632686 ```
633687 </Step>
634688
635 <Step title="Run your code">
689 <Step title="Run your code" stepNumber={7}>
636690 ```bash
637691 bundle exec ruby quickstart.rb
638692 ```