GunSpec
Atlas

Connect your app to GunSpec

For an app that acts for other people: a scheduler, a CMS, an agent platform. Each person connects their own GunSpec account once, and your app reads the catalogue as them, at their plan and under their limits, with no API key changing hands.

Apps are registered by GunSpec, one for each environment you run. Write to us with your app's name, its homepage and every redirect address it will use.

  • You receive a client id (gsapp_) and a client secret (gscs_). The secret is shown once and kept by us only as a hash: store it like any other server secret, never in a browser or a mobile app.
  • Redirect addresses are matched exactly, character for character, so register each one you use: production, a preview environment, and a loopback address for development. Production accepts https only.
  • A lost or leaked secret is replaced, not recovered. The old one stops working when the new one is issued; your connected people stay connected.

Authorization code with PKCE, as OAuth 2.1 requires. The server describes itself at /.well-known/oauth-authorization-server, so a generic OAuth client needs only the issuer.

connect.ts
typescript
import { authorizeUrl, createPkce, parseRedirect, exchangeCode } from '@buun_group/gunspec-sdk/oauth' // 1. Send the person to GunSpec. Keep the verifier and the state//    on your server, bound to this browser (a __Host- cookie).const pkce = await createPkce()const { url, state } = authorizeUrl({  clientId: process.env.GUNSPEC_CLIENT_ID,  redirectUri: 'https://app.example.com/integrations/gunspec/callback',  scopes: ['catalog.read'],  codeChallenge: pkce.challenge,}) // 2. On the callback: check the state and the issuer, then trade the code.const code = parseRedirect(request.url, state)const tokens = await exchangeCode({  clientId: process.env.GUNSPEC_CLIENT_ID,  clientSecret: process.env.GUNSPEC_CLIENT_SECRET,  code,  redirectUri: 'https://app.example.com/integrations/gunspec/callback',  codeVerifier: pkce.verifier,})// tokens.accessToken (gsat_, one hour), tokens.refreshToken (gsrt_, rotates)
  • Send the person to GET /oauth/authorize with response_type=code, your client_id, a registered redirect_uri, scope, a state and an S256 code_challenge. State and PKCE are both required.
  • They sign in to GunSpec if they need to and see your app's name and what it may do, then choose Allow or Deny. Deny returns error=access_denied to your redirect address.
  • Allow returns code, your state and iss. Check that the state is the one this browser was given and that iss is the GunSpec API origin before you use the code.
  • Trade the code at POST /oauth/token within ten minutes, authenticating with your client id and secret (HTTP Basic, or in the form). A code works once.
  • An unknown client or an unregistered redirect address never redirects: the person sees an error page at GunSpec, so a mistyped address cannot leak a code.

One scope today, and it is the catalogue.

  • catalog.read reads what the person's own key would read on /v1: firearms, specifications, calibers, media. It does not reach their account, keys, billing or favorites.
  • The one exception is your own webhooks: a token may manage the endpoints your app made for that person, and nothing else under /v1/me.

Call /v1 with the access token as a Bearer token. The request runs at the person's plan: a Builder account's token passes the Builder gate, and its calls count against their allowance.

call.ts
typescript
import { GunSpec } from '@buun_group/gunspec-sdk' // The person's access token, never an API key: the SDK sends it as Bearer.const gunspec = new GunSpec({ accessToken: tokens.accessToken }) const media = await gunspec.firearms.listMedia('glock-g17-gen5', { republish: 'free' })// Every item here may be posted with no credit line.
refresh.ts
typescript
import { refreshToken, GunSpecOAuthError } from '@buun_group/gunspec-sdk/oauth' try {  const next = await refreshToken({ clientId, clientSecret, refreshToken: stored.refreshToken })  await save(next) // the old refresh token is now spent: store the new one before using it} catch (error) {  if (error instanceof GunSpecOAuthError && error.error === 'invalid_grant') {    // The person disconnected, or a spent token was presented again.    // The connection is over: ask them to connect again.  }}
  • Access tokens (gsat_) last one hour. Refresh a minute or so before expiry rather than on the first 401.
  • Refresh tokens (gsrt_) last ninety days and rotate: every refresh returns a new one and spends the old. Store the new token before you use it, and refresh under a lock, because presenting a spent refresh token ends the whole connection.
  • A token for a connection that has ended answers 401 with reason KEY_INVALID. The person disconnected your app, or deleted their account: ask them to connect again.
  • On disconnect in your app, call POST /oauth/revoke with the refresh token. That ends the connection at GunSpec too, with every token and webhook it holds.
  • Never put an access token where an API key goes in a public place either. Keys in production applies to tokens just the same.

Every media item carries a rights block, derived from its recorded source, author and licence. Decide what to post from rights.republish, never by matching the credit strings, which are for showing a credit line.

rights.republishWhat it allows
freePost it with no credit line. Our own renders, silhouettes and drawings, and anything in the public domain or under CC0.
with_creditPost it only with the source, author and licence from credit beside it. A CC BY family licence.
noDo not post it. A NonCommercial licence, a licence we do not recognise, or none recorded.
  • rights.owner says whose it is (gunspec, third_party or unknown) and rights.license the licence as recorded.
  • GET /v1/firearms/{id}/media?republish=free lists only what needs no credit line.
  • Silhouettes and line art are SVG, which no social platform takes. Their items carry a png block of URLs for a PNG copy at each size, on a white ground unless you ask for background=transparent. See Firearm media.

Your app can subscribe on a person's behalf, so an automation runs when something changes instead of on a timer. Call the webhooks endpoint with their access token.

Terminal
bash
curl -sS -X POST https://api.gunspec.io/v1/me/webhooks \  -H "Authorization: Bearer $GUNSPEC_ACCESS_TOKEN" \  -H "Content-Type: application/json" \  -d '{    "url": "https://app.example.com/hooks/gunspec",    "events": ["media.created", "firearm.updated", "firearm.created"],    "firearmIds": ["glock-g17-gen5", "sig-sauer-p320"]  }'
  • Three events: firearm.created for a new firearm, firearm.updated for a changed specification, and media.created for a new picture, which carries the media item with its rights.
  • firearmIds narrows firearm.updated and media.created to the firearms a workspace follows. firearm.created always arrives, since nobody can follow a firearm that did not exist.
  • App webhooks work from the Builder plan up. Five endpoints for each connection.
  • Your app sees only the endpoints it made for that connection. The person sees them in their account too, marked with your app, and every one is deleted when the connection ends.
  • Deliveries are signed exactly as every GunSpec webhook is: verify X-Webhook-Signature and dedupe on X-Webhook-Id. See Mirror the catalog for a receiver.

Show the connected account on your connection panel from GET /oauth/userinfo: who it is, their plan, and what is left of their allowance.

Terminal
bash
curl -sS https://api.gunspec.io/oauth/userinfo -H "Authorization: Bearer $GUNSPEC_ACCESS_TOKEN" {  "sub": "usr_...",  "email": "person@example.com",  "name": "A. Person",  "plan": "builder",  "usage": {    "plan": "builder",    "limits": { "daily": 5000, "monthly": 25000 },    "remaining": { "daily": 4870, "monthly": 21342 },    "mcpDaily": 500  }}
  • usage.limits are the plan's daily and monthly request limits and usage.remaining what is left of each now. A limit the plan does not have is null. usage.mcpDaily is the daily limit for MCP tool calls.
  • Every /v1 answer to a Bearer call carries the same X-Daily-* and X-Monthly-* headers as a call with a key, so you can pace against them without asking again.
  • Reading userinfo spends nothing. See Rate limits for how the limits work.