Home » AI Databases » Key-Value Setup

How to Set Up a Key-Value Database for Your App

Setting up a key-value database on the AI Apps API platform takes less than a minute. Install the NoSQL app, and you have a fully managed database ready to store and retrieve data using simple API calls. There is no server to configure, no schema to design, and every read or write operation costs just 1-2 credits.

Before You Start

The platform's key-value database uses a two-key system: a partition key (called pid) and a sort key. The partition key groups related records together, and the sort key identifies individual records within that group. For example, in a game you might use the player ID as the partition key and the game session ID as the sort key. In a business app, the company ID could be the partition key with record types like "settings" or "profile" as sort keys.

Think about how you want to organize your data before you start. The partition key is how you will look up groups of records, and the sort key lets you query within those groups. You do not need to define this structure upfront in any configuration file, just decide on a convention and use it consistently in your API calls.

Step-by-Step Setup

Step 1: Install the NoSQL app.
Log into your admin panel and find the NoSQL app in the app directory. Click Install to add it to your account. Unlike the MySQL and PostgreSQL apps, there are no connection details to enter because the database is built into the platform.
Step 2: Create your first record.
Use the NoSQL app's API to insert your first record. Send a POST request with your partition key, sort key, and the data you want to store. The data can be any JSON object: player stats, user preferences, product listings, or anything your app needs. The record is created instantly and available for retrieval.
Step 3: Read your data back.
Retrieve a single record by specifying both the partition key and sort key. Or query all records under a partition key to get a group of related items. For example, fetch all game sessions for a player by querying with the player ID as the partition key.
Step 4: Update individual fields.
Update specific fields on an existing record without rewriting the entire object. This is efficient for counters, status changes, and incremental updates. For example, update just a player's score or a product's stock count without touching the rest of the record.
Step 5: Delete records when needed.
Remove records by specifying their partition key and sort key. You can also set a TTL (time to live) when creating records so they expire automatically after a set period, which is useful for session data, temporary tokens, and cache entries.

Key Design Patterns

One Record Per Entity

The simplest pattern: one partition key per user or entity, one sort key for each piece of data. A user profile might use pid="user-12345" with sort keys like "profile", "settings", and "preferences". This keeps all of a user's data grouped together for easy retrieval.

Time-Series Data

For data that accumulates over time (activity logs, sensor readings, transaction history), use the entity ID as the partition key and a timestamp as the sort key. This lets you query records in chronological order and filter by date range. Example: pid="device-001" with sort keys like "2026-03-19T10:30:00".

Game Leaderboards

Store player records with the game ID as the partition key and the player ID as the sort key. Each record holds the player's score, name, and stats. Query all records under a game ID to build the leaderboard. See How to Store Player Profiles and Leaderboards for a complete walkthrough.

Cost example: A mobile app making 5,000 database operations per day (reads and writes combined) would cost about 5,000-10,000 credits per day, or roughly $5-10 per month. This covers user profiles, settings, activity logs, and any other data the app needs to store and retrieve.

Connecting From External Apps

The NoSQL database is accessible through the platform's API, which means any application that can make HTTP requests can use it. Mobile apps (iOS and Android), Unity games, web frontends, and server-side scripts can all read and write data through the API. You just need your API key and account ID to authenticate requests.

If you are building a game or mobile app that needs a backend database, this is one of the fastest ways to get started. There is no server to deploy, no database to manage, and the API handles authentication and data validation automatically. For game-specific guidance, see How to Build a Game Backend With NoSQL.

What You Can Do Next

Once your key-value database is running, explore storing custom app data, syncing data with AI workflows, or connecting the database to a chatbot so users can query their own data through conversation.

Set up a key-value database in seconds. No servers, no schema, no monthly hosting fees.

Get Started Free