
Quickstart
What is AI Declare?
AI Declare is an AI agent for REST API code generation. The way you configure the agent is by using a DSL (Domain Specific Language). The DSL is embedded in the Scala programming language, and it allows to the programmers to create complex secured REST APIs in just a few minutes in different languages / frameworks.
Prerrequisites
Basic programming skills are a prerequisite..
IntelliJ IDEA (Community or Ultimate) + Scala plugin
Install IntelliJ IDEA.
In Settings → Plugins, search Scala and install it.
(Recommended) JDK 21+, Scala 3.3+, sbt 1.10+.
ChatGPT API token (OpenAI API key)
Create/get your API key from your OpenAI Platform account.
Top up some credit here
Register as a user here
Your first AI Declare project
1) Setup environment
Register as a user here
Setup your AI Declare credentials
2) Setup a Scala project
Open IntelliJ IDEA
New Project → Scala → sbt.
Choose your JDK, set Scala 3.x (any recent 3.x).
Name the project (e.g.,
aideclare-sample) → Create.
This generates:
build.sbtproject/build.propertiesproject/directory for sbt metadata
Add the following code to build.sbt
Sync the project
3) Implementation
Data model definition
First, define your data model. Create one Scala case class for each table in your database. Mark primary keys with @id and foreign keys with @fk, and have every case class derives EntityMetadata.
If a case class represents an application user, also derive UserInfo. In that case, annotate the username and password fields with @username and @password, respectively.
APIs definition
Next, define your REST APIs. You can expose four kinds of endpoints:
Public: open to everyone; no authentication required.
Authenticated: access restricted to specific user types/roles.
Me: operate on the authenticated user’s own data.
Sub-APIs: endpoints nested under another API; they inherit the parent’s access controls.
4) Create a project in AI Declare site
On the AI-Declare site, create a new project, then select the target language and framework for code generation.

5) Run an execution
Create a main class like the following
When you run the code you will be asked to choose a project:
6) Download the code from Executions screen
That's it, the code will be generated in a few minutes and you will be able to download it from the web site.

Click in the file icon to download generated sources.
Last updated