# Use the API with AI tools

> Connect your Ur Next Door API key to Claude Code, Codex CLI or a ChatGPT custom GPT, and what Claude Desktop needs. Safety rules for agents that post as you.

Source: https://docs.urnextdoor.com/ai/

An AI agent with your key can draft, illustrate, schedule and publish content for you. The API was designed for this: it has an [OpenAPI document](https://docs.urnextdoor.com/reference/openapi.md) that agents can read, an [llms.txt](https://docs.urnextdoor.com/llms.txt) index of these docs, a clean Markdown copy of every page, and a [ready system prompt](https://docs.urnextdoor.com/ai/system-prompt.md).

## Which tool, and how

| Tool | Works today? | How it calls the API | Guide |
| --- | --- | --- | --- |
| Claude Code (terminal, IDE or the Code tab of the Claude desktop app) | Yes | Runs `curl` with your key from an environment variable | [Claude Code](https://docs.urnextdoor.com/ai/claude-code.md) |
| Codex CLI | Yes, after you enable network access | Runs `curl` with your key from an environment variable | [Codex CLI](https://docs.urnextdoor.com/ai/codex-cli.md) |
| ChatGPT custom GPT | Yes, with limits on images | GPT Actions, imported from the OpenAPI URL | [ChatGPT Actions](https://docs.urnextdoor.com/ai/chatgpt-actions.md) |
| Claude Desktop chat and claude.ai | Not yet | Needs an MCP server; an official one is on the roadmap | [Claude Desktop](https://docs.urnextdoor.com/ai/claude-desktop.md) |
| Your own agent or script | Yes | Any HTTP client | [Reference](https://docs.urnextdoor.com/reference.md) |

## Rules every agent should follow

These are built into the [system prompt](https://docs.urnextdoor.com/ai/system-prompt.md). Paste it into your tool so you do not have to repeat them:

1. **Read the key from `UND_API_KEY`, never print it.** The agent should never echo, log or write the key, and never put it in a URL.
2. **Confirm before publishing.** Public content goes out under your name. Ask the agent to show a preview and wait for your yes, unless you said otherwise.
3. **Upload images first, then use `data.url`.** See [Upload images](https://docs.urnextdoor.com/guides/upload-images.md).
4. **Look ids up, never invent them.** Communities, categories, job options and places come from the [lookups](https://docs.urnextdoor.com/guides/lookups.md).
5. **Send an `Idempotency-Key` on every create**, so a retry never posts twice.
6. **Schedule in UTC with `Z`**, between 5 minutes and 180 days ahead, and say both times back to you.
7. **Handle errors properly.** On `422`, fix the named fields. On `429`, wait `Retry-After` and report the remaining quota.
8. **Finish with links.** Return the `web_url` of everything created.

## Give each agent its own key

Create one key per tool, with only the [scopes](https://docs.urnextdoor.com/getting-started/scopes.md) it needs, and a short expiry. Then [API analytics](https://docs.urnextdoor.com/analytics.md) shows what each agent did, and you can revoke one without touching the others.

## Next steps

- [Claude Code](https://docs.urnextdoor.com/ai/claude-code.md): set the key, add a CLAUDE.md note, allow curl.
- [Codex CLI](https://docs.urnextdoor.com/ai/codex-cli.md): set the key, AGENTS.md, and turn on network access.
- [ChatGPT Actions](https://docs.urnextdoor.com/ai/chatgpt-actions.md): import the OpenAPI URL and keep the GPT private.
- [System prompt](https://docs.urnextdoor.com/ai/system-prompt.md): the copy-paste rules for any agent.
- [Prompt recipes](https://docs.urnextdoor.com/ai/prompt-recipes.md): prompts that work well.
- [Claude Desktop](https://docs.urnextdoor.com/ai/claude-desktop.md): what it needs, and what to use meanwhile.
