# Claude API

> Add Claude to your own app so it can do a job for your users, such as summarizing a document they provide.

Web page: https://buildladder.com/tools/claude-api

Imagine a book club site where readers paste their meeting notes and get a short recap. Your app can send the notes and a request for a recap to Claude through an API, a way for two programs to exchange information.

Try it with a sample meeting that includes two decisions and one unresolved question. Compare the answer with the notes. Does the recap preserve the decisions without presenting the open question as settled?

- Made by: Anthropic
- Official site: https://platform.claude.com/docs/en/get-started
- Cost: Pay per use with prepaid credits. New users get a small amount of free credits to test. On November 9, 2026, Claude Haiku 5.5 cost $0.10 per million input tokens and $0.50 per million output tokens, for prompts up to 100,000 tokens.
- What you need first: A Claude Console account, some credits, and an API key. The key is a secret code your app’s server uses to call Claude.
- Who it helps: When your app needs to write, summarize or answer questions with Claude.
- When to skip it: If you only want an AI tool to write your code. You need it only when your finished app uses AI itself.
- Updated: 2026-11-09

## Add AI features with the Claude API

Add one AI feature from your plan, like a summary or a helper chat, using Anthropic’s Claude API. Your app calls Claude from its server, so your key stays secret.

What you’ll end up with: One AI feature from your plan, working in your app, with a spending limit set and your key kept out of your code.

### You’ll need

- A website or app you started, open in your AI tool.
- PLAN.md from the Plan your idea guide.
- A payment card, to buy credits.
- Claude Console account (https://platform.claude.com): It holds the credits your app spends

### Your part

- Create the Claude Console account and set a spending limit.
- Create the API key and paste it into your .env file.
- Try the feature and check what it cost.

### Step 1 of 5: Create an account and set a spending limit

This step is mine to do. Walk me through it, one action at a time:
- Go to platform.claude.com and sign up for a Claude Console account.
- Open the Billing page in Settings to see your credit balance.
- If you need more credits, click Buy credits, enter a small amount and confirm.
- Leave auto-reload off. If the Credit balance section shows Manage auto-reload, it’s on. Click it, then click Turn off twice.
- In the Spend limits section, click Set limit. Enter the most you’re happy to spend in a month.

It worked when: Your Claude Console account has credits, auto-reload is off, and the Spend limits section shows your monthly limit.

Before we move on, check with me:
- Does the Billing page show a Set up auto-reload button, which means auto-reload is off?

If something goes wrong:
- The Spend limits section shows Adjust limit instead of Set limit. A limit is already set. Click Adjust limit to check it or change it.
- You can’t enter a limit as high as you want. Your limit can’t go above your account tier’s monthly cap. That cap is $500 a month on the Start tier.
- The payment doesn’t go through. Check the card details, or try another card. Contact Anthropic’s support if it keeps failing.

### Step 2 of 5: Create a key and save it in .env

This step is mine to do. Walk me through it, one action at a time:
- In the Claude Console, open the API keys page in Settings and click Create key.
- Name it after your app. Choose how long it lasts. When a key expires, your app stops working until you make a new one.
- Set Linked account to yourself. Scope the key to one workspace, like the Default Workspace, so your app needs no extra settings.
- Copy the key. Paste it only into your .env file, never into the chat.
- In your product’s folder, open the file named .env. If there isn’t one, ask your AI tool to create an empty one, then open it yourself.
- Add the line ANTHROPIC_API_KEY=your-key, with your real key and no spaces. Save the file.
- Don’t save a version yet. “Add one AI feature” first checks that Git leaves your .env file out.

It worked when: Your .env file holds your key, and it is saved only on your computer.

Before we move on, check with me:
- Does the line start with ANTHROPIC_API_KEY= and have no spaces?

If something goes wrong:
- You lost the key or pasted it somewhere public. Click Delete next to it on the API keys page and create a new one. Then update the line in your .env file.

### Step 3 of 5: Add one AI feature

Read PLAN.md in this folder. It has my plan and the tools I chose.

I want to add one AI feature that uses the Claude API. Pick the one feature from my plan that fits best, like a summary or a helper chat. Tell me which one and wait for my OK.

Before you write code:
- Check that .env is listed in .gitignore. If it isn’t, add it. Don’t open or print .env.
- Create .env.example with only the variable name ANTHROPIC_API_KEY and no value.
- Check Anthropic’s current official docs for the right library and a current, low-cost model.

Then build the feature:
- Call Claude only from server code, like an API route or a server function. Never call it from the browser or the phone app.
- Read the key from the ANTHROPIC_API_KEY environment variable. Never put the key in code, logs or Git.
- Never use a variable name the browser or app can read, such as one starting with NEXT_PUBLIC_ or EXPO_PUBLIC_.
- If my app has no server part yet, suggest the simplest one for my setup and ask me first.
- Cap the answer length with the max_tokens setting, so each answer stays short and cheap.

Keep everything that already works.

It worked when: Your app shows an answer from Claude when you try the feature on your computer.

Before we move on, check with me:
- Does your AI tool say the file that calls the API is server code, not a page or screen?

If something goes wrong:
- It says the API key is missing or invalid. Check that the line in your .env file starts with ANTHROPIC_API_KEY= and has no spaces. Then restart your app so it reads the file again.
- It says the API key is not scoped to a workspace. Create a new key on the API keys page and scope it to one workspace. Then update the line in your .env file.
- It says your credit balance is too low. Add credits on the Billing page in the Claude Console, then try again.
- You get a rate limit error after only a few tries. New accounts start with lower limits. Wait a minute and try again. The limits go up as you use the API.

### Step 4 of 5: Handle waiting, errors and limits

My AI feature works. Now make it safe and friendly to use.

Check Anthropic’s current official docs for the errors the Claude API can return, including rate limits and spend limits. Then:
- Show a clear loading message while the answer is on its way, and stop people from sending the same request twice.
- Show a short, friendly message when something fails. Keep the real error in the server logs only, and never log the key.
- Give these cases their own plain message: too many requests (a rate limit), out of credits or over my spending limit, and the service being busy.
- Don’t keep retrying when my spending limit is reached. Claude says retrying fails until the limit is raised or the month resets.
- Limit how long a person’s input can be, and keep the answer length capped.
- Add a simple limit on how many times one person can use the feature in a short time, so nobody can run up my bill.

Keep everything that already works. Make only these changes. Then give me a short list of things to try, and what I should see for each one.

It worked when: Your feature shows a loading message and friendly errors, and stops one person from using it too often.

Before we move on, check with me:
- When you send an empty box, is the message helpful?
- When you paste in a very long text, does it stop you politely?

If something goes wrong:
- You can’t make an error happen to test it. Ask your AI tool to show you how to fake each error for a moment on your computer, then undo it.

### Step 5 of 5: Try it and check the cost

This step is mine to do. Walk me through it, one action at a time:
- Use the feature five times with real examples from your plan.
- Make a mistake on purpose, like sending an empty box. Check the message makes sense.
- Ask your AI tool to build the app and check that your key is in no file a visitor’s browser or phone downloads.
- Open the Usage page in the Claude Console and see what those tries cost.
- Write the cost of one use into PLAN.md. If it’s too high, ask your AI tool for a cheaper model or shorter answers.
- When you put your app online, add the same key in your host’s settings. The .env file doesn’t go online.

It worked when: The feature works with real examples, your key stays hidden, and you know roughly what one use costs.

If something goes wrong:
- Your app stopped working online after a few weeks. The key may have expired, and an expired key can’t be turned back on. Create a new one, then update your .env file and your host’s settings.
- The feature works on your computer but not online. Your host needs the key too. Add ANTHROPIC_API_KEY in its settings, then put your app online again.

Compare Claude API with the other options: https://buildladder.com/concepts/ai-features.md
