Skip to main content

Connect an API

When. The station reads or writes at a tenant: its catalogue, its slots, its orders. Every tool of a station is an operation of an API declared here.

Steps​

  1. Name the API and give its spec (openapi_url) and its address (base_url): a public address (a domain name). A local or private address is refused at the check.
  2. List the operations it uses, and only those, under operations, each by its operationId as the spec writes it, with access: read (changes nothing at the tenant) or access: write (changes something: only a confirmed submit calls it).
  3. Choose the authentication (auth.type):
    • none: a public API;
    • api_key: key_name (the header or parameter that carries the key), key_location (header or query) and key_env;
    • bearer: token_env (sent as Authorization: Bearer …);
    • basic: username_env and password_env.
  4. Grant every operation to a profile (profiles): everything is closed by default. See Decide who may do what.
  5. Check the config, then publish. If the API reads a key, save it on the station's key page (the key-page skill of the Convoy station gives its link), then confirm the same publication again.

The example​

connect-an-api.yaml
# Connect an API: its OpenAPI, its address, the operations the station may reach, and its key —
# the config names the variable, the value is saved on the station's key page, never here.
# Replace api.example.com by the API.
station:
id: shop-catalogue
name: Shop Catalogue

global:
language: en
currency: EUR
locale: en-GB

domain:
domain_type: retail
entity_name: product
entity_name_plural: products

voice:
tone: friendly
persona: "a shop assistant who knows the catalogue"
rules:
- "Never invent a product or a price: everything comes from the tool."

apis:
- name: shop
openapi_url: https://api.example.com/openapi.json # the spec Core reads the operations from
base_url: https://api.example.com # where the calls go: a public address
operations: # an allowlist: nothing else is reachable
- {id: searchProducts, access: read} # declared, never guessed from the verb
auth:
type: api_key
key_name: X-API-Key # the header the API reads the key from
key_location: header
key_env: SHOP_API_KEY # a NAME: the value goes on the key page

profiles: # everything is closed until granted
everyone:
when: "true"
grants: [shop.searchProducts]

skills:
- name: products
cognitive:
objective: "answer about the shop's products: what exists, its price, whether it is in stock"
params:
q: {type: text, set_by: [llm]} # the person's words, given by the model
invoke:
method: searchProducts
args: {q: "$params.q"}

The pitfalls​

  • The key is never in the config. key_env names a variable; its value is pasted on the key page, never in the file nor in the conversation. A key: or token: written in auth is refused (unknown key).
  • A variable named with no value saved refuses the publication, naming the variable: the station is registered without starting. Save the key, then publish again.
  • A known production key (sk_live_, rk_live_) is refused: stations run on test accounts.
  • The key goes to its hosts only. It is saved with the hosts of the base_urls that read it; a config that moves base_url to another host is refused.
  • access is declared, never guessed from the HTTP verb: a search is often a POST. A write operation in a skill's invoke is refused ("a write is reserved"); so is a submit through a read operation (it would file nothing).
  • An operation missing from operations cannot be reached, even if the spec describes it. Do not list a write that nothing uses.
  • An operation no profile is granted is refused at load: it would be refused to everyone.
  • An argument the operation requires that the skill does not send refuses the station: declare it in params and send it through invoke.args.

What Core says, and the fix​

Each sentence below is Core's own, as it answers today (a test keeps them true):

  • "names capability 'searchProduct', which does not exist" — fix: write the operationId exactly as the spec does (searchProducts), and list it under operations.
  • "and no profile is granted it — closed by default, it would be refused to everyone" — fix: add <api>.<operationId> to a profile's grants.
  • "auth.key: Extra inputs are not permitted" — fix: never a key in the config: key_env names it, its value goes on the key page.

Reference: Sources, Your APIs' keys.