// Stay in touch?
Products
Encore CloudEncore Cloud
Encore.tsEncore.ts
Encore.goEncore.go
PricingPricing
Book a DemoBook a Demo
Use Cases
AI-Powered DevelopmentAI-Powered Development
Event-Driven SystemsEvent-Driven Systems
Distributed SystemsDistributed Systems
Case StudiesCase Studies
ShowcaseShowcase
Resources
DocsDocs
InstallInstall
Example AppsExample Apps
Demo videoDemo video
ArticlesArticles
ResourcesResources
GitHub ReleasesGitHub Releases
Systems Operational
Company
About UsAbout Us
Swag ShopSwag Shop
ContactContact
JobsJobs
PressPress
TermsTerms
Privacy PolicyPrivacy Policy
Data Processing AgreementData Processing Agreement
Enterprise SLAEnterprise SLA
Encore
© 2026 EncoreAll rights reserved
© 2026 Encore All Rights Reserved
GitHubDiscordYouTube

See all Templates

AI Agent Backend

Build an AI-powered agent API with tool use and conversation management

Tags

AI
API

Use Case

Starter

Author

Encore

Repo

Open on GitHub
Open on GitHub

Run this template in 60 seconds by installing Encore:

macOS
Windows
Linux
Brew
$ brew install encoredev/tap/encore

Or deploy it directly to your cloud:

EncoreDeploy with Encore

AI Agent API Backend

A backend for building AI-powered applications using Encore.ts and Claude.

Deploy to Encore

Architecture

This app has two services:

  • chat — Manages conversation sessions and message history (Postgres DB). Exposes the public API.
  • ai — Internal service that calls the Anthropic Claude API to generate responses.

Prerequisites

  • Encore CLI
  • An Anthropic API key

Getting Started

  1. Set the Anthropic API key as a secret:
encore secret set --type dev,local,pr,prod AnthropicAPIKey
  1. Run the app:
encore run

The Postgres database is provisioned automatically on startup. Encore runs the migrations and manages the database for you — no manual setup required.

Open http://localhost:4000 for usage instructions, or http://localhost:9400 for the Local Dashboard. When deployed to Encore Cloud, use the Service Catalog to call endpoints and view traces to see how requests flow between services.

API Endpoints

Send a message

curl -X POST http://localhost:4000/chat \ -H "Content-Type: application/json" \ -d '{"message": "What is Encore?"}'

Returns a session_id you can use for follow-up messages:

curl -X POST http://localhost:4000/chat \ -H "Content-Type: application/json" \ -d '{"message": "Tell me more", "session_id": "<session_id>"}'

Get conversation history

curl http://localhost:4000/chat/<session_id>

List all sessions

curl http://localhost:4000/chat