Build with an AI assistant
Many programs that use the API will be written with an AI coding assistant (Claude Code, Cursor, Copilot and the like). The API is built to make that go well: one OpenAPI file describes everything, every error says how to fix itself, and there’s usually one obvious way to do each thing.
Give the assistant the API
Section titled “Give the assistant the API”Start your conversation with something like this:
I'm writing a program that uses the Farkitect API.- Base address: https://api.farkitect.com/v1- Its OpenAPI file: https://api.farkitect.com/openapi.json- Its guides, as plain text: https://docs.farkitect.com/llms-full.txt- My API key is in the environment variable FARKITECT_API_KEY. Never put the key in code, logs or a web page.- Errors are RFC 9457 problems: branch on `code`, and show `detail`.- On 429, wait the seconds in Retry-After and try again.- Ignore response fields you don't recognise.Start by calling GET /v1/me to check the key works.Then describe what you want the program to do.
llms.txt and llms-full.txt are the convention AI tools look for: the first is a short index of these docs, the second all the API guides in one plain-text file.
Web apps: keep the key on a server
Section titled “Web apps: keep the key on a server”The API refuses calls from web pages (browser_not_allowed): a key in a page, or in a browser app’s code, can be read by anyone who uses it. So a web app needs a small piece of server code that holds the key and passes calls on. Ask your assistant to use this pattern.
A Next.js route, which also works as a Vercel function (app/api/farkitect/[...path]/route.ts):
// Passes GET requests on to the Farkitect API, adding the key, which stays// on the server. Only the paths listed here can be reached through it.const ALLOWED = [/^me$/, /^projects(\/.*)?$/];
export async function GET(request: Request, { params }: { params: Promise<{ path: string[] }> }) { // Check your own users here first: anyone who can reach this route can use your key. const path = (await params).path.join("/"); if (!ALLOWED.some((pattern) => pattern.test(path))) { return new Response("Not available", { status: 404 }); } const query = new URL(request.url).search; const response = await fetch(`https://api.farkitect.com/v1/${path}${query}`, { headers: { Authorization: `Bearer ${process.env.FARKITECT_API_KEY}` }, }); return new Response(response.body, { status: response.status, headers: { "Content-Type": response.headers.get("Content-Type") ?? "application/json" }, });}Your page then calls /api/farkitect/me on its own site, and never sees the key. Set FARKITECT_API_KEY in the hosting service’s environment settings, not in the code.
Two things to keep in mind:
- Your route is open to anyone who can reach your site unless you check your own users first. Keep
ALLOWEDto what the page needs. - Apps used by other organisations need each organisation’s own consent, not your key. That’s what “Sign in with Farkitect” (OAuth) will be for, in a later phase.
Keys and repositories
Section titled “Keys and repositories”Quickly written projects are often pushed to a public repository. Keep the key out of every file that’s committed: in a .env file listed in .gitignore, or in the hosting service’s settings. If a key is ever committed, revoke it in Organisation › Developers and make a new one; deleting the commit doesn’t make it safe again.