1KEY Developers
Build with AI

Build with AI assistants

Point your AI coding assistant at these docs and it can write 1key integrations for you. This page has the files assistants read, instructions to give them, and prompts to start from.

Files for assistants

File Contents
/llms.txt Index of these docs, with links to each page as Markdown
/llms-full.txt All of these docs in one Markdown file
/openapi.yaml The OpenAPI 3.1 contract
/docs/<page>.md Any page as Markdown, for example /docs/events.md

Give the assistant llms-full.txt and openapi.yaml when it should write code; llms.txt is enough for it to find answers.

Instructions for your assistant

Paste this into your assistant's project instructions (CLAUDE.md, AGENTS.md, .cursorrules or similar):

markdown
## 1key API

Docs: https://developers.1keyplatform.dev/llms-full.txt · Contract: https://developers.1keyplatform.dev/openapi.yaml

- Base URL: https://api.1keyplatform.dev/v1. Auth: `Authorization: Bearer $ONEKEY_API_KEY`. Read the key from the environment; never hardcode, log or commit it.
- Hub IDs look like `1key-xfy2-nmf4-5xwp`. A hub outside our organization returns 404.
- Device state lives on the hub. Devices have channels ({key, endpoint}); GET /hubs/{hub_id}/devices/{device_id} returns each channel's value, desired and status, read live. Follow changes with events. Do not build a local cache of device state and treat it as truth.
- Commands: POST /hubs/{hub_id}/devices/{device_id}/commands with {"key", "value", "endpoint"?}, only on writable channels. Always send an Idempotency-Key header (a new UUID per logical command, reused on retries). 202 means the hub accepted it (status pending), not done: the outcome is the channel's next channel.observed event, or its status (synchronized, diverged, failed) on GET device.
- Events are per hub. Read GET /hubs/{hub_id}/events?after={cursor}&wait=30 in a loop and persist next_cursor after handling each page. Cursors are opaque strings. Deduplicate on (hub_id, cursor). On 410 cursor_expired, re-read devices and continue from the newest event.
- Retry 429 (honor Retry-After), 500, 503 and 504 with exponential backoff and jitter. Never retry 400, 401, 403, 404 or 409.
- Branch on error.type, never on error.message.
- Ignore event types you do not handle; new ones appear without a version change.

Suggested prompts

Start from one of these, then adjust.

List hubs and devices

Using the 1key API (https://developers.1keyplatform.dev/llms-full.txt), write a script that lists every hub in my organization with its connection status, then lists the devices of each online hub. Read the API key from ONEKEY_API_KEY. Handle pagination and 503 hub_offline.

Unlock a door safely

Write a function unlock(hubId, deviceId) for the 1key API that sets the device's lock channel to false with an Idempotency-Key, then polls the device for up to 10 seconds until the lock channel's status is synchronized, diverged or failed, and returns that or still-pending. Retry only on network errors, 429, 502, 503 and 504, reusing the same Idempotency-Key.

Follow events from all hubs

Build a long-running worker for the 1key API that follows events from every hub in my organization. One reader loop per hub using GET /hubs/{hub_id}/events with wait=30. Persist each hub's cursor in SQLite after handling a page, deduplicate on (hub_id, cursor), handle 410 cursor_expired by resyncing devices, and pick up hubs that are added later.

Generate a typed client

Generate a typed TypeScript client from https://developers.1keyplatform.dev/openapi.yaml with one method per operationId, typed errors keyed on error.type, automatic Idempotency-Key on sendCommand, and retries that follow the 1key retry rules.

Explain an error

I got this response from the 1key API: <paste response>. Using https://developers.1keyplatform.dev/docs/errors.md, explain what went wrong and whether I should retry.

Letting an AI agent operate devices

An agent that sends commands acts on real doors and thermostats. Set it up so a mistake is contained.

  • Give agents their own keys with the fewest scopes. An agent that reports status needs only hubs:read and events:read. Leave out hubs:command unless it must act.
  • Confirm before physical actions. Have a person approve unlocks and any action on a door before the agent sends it, and show which hub and device it will touch.
  • Send an Idempotency-Key with every command, so an agent retrying in a loop cannot unlock a door twice.
  • Check the outcome before reporting success. 202 means accepted, not done.
  • Revoke the agent's key from the API keys page to stop it at once.