Building Claude into Your Own App
On this page11 items
In 10 seconds
Getting it running is easy. The hard part is what to do when it fails.
Broken output, hitting limits, unpredictable costs. Design for these three first.
This page wraps up Chapter 7. So far we’ve covered how to call the API (#51), its features (#52), costs (#53), and turning it into an agent (#54).
The last topic is what it takes to actually run it inside your organization.
Running it is easy; keeping it running is hard#
A prototype takes a day. Running it in production for three months is the hard part. The difference lies in how you handle failure.
Here are the three things to decide up front.
When the output breaks#
Use structured outputs (#52). That guarantees the shape.
However, a correct shape and correct content are two different things. Just because the date field contains a date doesn’t mean it’s the right date.
Build in sanity checks. The three described in Chapter 4, #33 apply as is.
- Count: If there were 5 inputs, are there 5 outputs?
- Edges: Are the first and last items plausible?
- Diff: Compared with the previous result, can you explain how it changed?
And use a type that can express “couldn’t read this.” Not an empty string, but null, or a “needs review” flag. Being unable to tell a guessed value from an unreadable one is the scariest state of all.
When you hit limits#
You will hit rate limits (#51). It’s a certainty.
Don’t retry immediately. Each SDK includes a mechanism that retries with a delay. Use it.
Decide what to return when you hit the limit. An error, a queue, or the previous result? If there’s a person on the other side of the screen, telling them “We’re busy right now” is kinder than making them wait.
The proper approach for anything non-urgent is to move it to batch processing (#53). Ask yourself once whether it really needs to be processed in real time.
When costs are unpredictable#
After making the estimate from #53, put in place a mechanism that sets limits.
- Set a spend limit on the workspace in the Console
- In your own app, count the number of calls per day
- Set per-user limits (if you put it in your own service)
Skip the third one, and a single user’s usage can bring the whole thing to a halt.
And keep a record of usage. The usage field in the response contains the token counts. Saving it lets you see later “which processes are expensive.”
Key management, once more#
To repeat what #51 said: never put the key on the client side.
If you put it in your own service, always route through your own server. If the browser or app calls Claude directly, users can see your key.
With a server in between, you can put limit management, logging and filtering there too. It’s the natural design.
Who is responsible#
This is about operations, not technology. Don’t go to production without settling this.
- Who notices when the output is wrong?
- Whose call is it to stop it?
- What do you tell users?
As Chapter 3, #22 said, delegating doesn’t transfer responsibility. “The AI produced that result” is not an excuse.
Also decide whether to tell users that AI is involved. In some fields, not telling them is a problem in itself. This is covered in Chapter 11, #79.
Ship small#
Finally, a word about order.
- Use it with a few people inside the organization
- Collect a record of failures (which inputs broke it)
- Add sanity checks
- Widen the scope
Don’t skip step 2. The inputs you actually get differ from what you expect. In the quotes example, it’s the one vendor with a different format, the one page scanned at an angle, the one entry with an empty amount field. Designing after those show up gives you a more accurate system.
Try it: Identify the failure modes up front (5 minutes)
Prompt
“`
I’m going to build the following process with the API and run it in production.
List the “failures that could happen,” grouped by cause.
- Input problems (unexpected data)
- Output problems (correct shape, wrong content)
- Environment problems (limits, outages)
- Operational problems (nobody notices)
For each one, also describe countermeasures that can be built in ahead of time.
Please suggest solutions based on code or mechanisms, not willpower.Process: (describe it here)
“`Expected result: Failures and countermeasures come back in four categories. You can see that the fourth, “nobody notices,” is the scariest.
If it doesn’t work: If the countermeasures are all “check it,” add “only countermeasures that don’t rely on human attention.” It’s the same point as Chapter 5, #41.
Common pitfalls#
Treating a successful prototype as a production forecast. Working on 10 items doesn’t mean something different won’t happen at 10,000.
Filling unreadable values with blanks. You can no longer tell them apart from guessed values.
Not setting a cost limit. Build the possibility of a bill ten times higher than expected into your design.
Not building a way to notice. A system that keeps quietly getting things wrong is the most dangerous shape discussed in this whole chapter.
Where to go from here#
This is the end of the main development route. If you’ve read Chapter 1 → Chapter 3 → Chapter 5 → Chapter 6 → Chapter 7, you’ve gone all the way through using Claude, delegating to it, connecting it and building it in.
From here, there are two paths depending on your goal.
- If you’re moving into operations → Chapter 11, Security and privacy (#78). What is safe to hand over, how to create internal rules, and how to live with mistakes (#80)
- If you want to build more → Chapter 10, Personal development: from zero to launch (#77)
Chapter 8 (using it at work) and Chapter 9 (using it in daily life) are collections of practical examples organized by use, not by technology. You don’t need to read them in order, so open whichever page interests you.
Summary#
- Running it is easy. The hard part is handling failure
- A correct shape and correct content are two different things. Build in sanity checks
- Make unreadable values distinguishable from guessed values
- Decide who notices and who stops it before going to production