Obter uma chave de API
Conceitos

Armazenamento de sessões

Se la sessione catched è mantenida è decisa dal tempo d'esecuzione — un file, localStorage, o memoria. Può sostituirlo con tre metodi.

read · write · clear
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Ce obten per default

Tempo di esecuzioneManteneva inSobrevivèncias
nodo~/.iagenify/session, in un directory creato con modo 0700reavizia
NavegatoreLocalStorage, sotto iagenify_sessionrecarghe, per origine
- operàMemóriaSolo l'isolado

In Node, sessionPath move il file. In ogni altra parte il luogo è fixed, e la forma di cambiarlo è di fornire il vostro storage.

Fornecendo il tuo

Tre metodi async. read restituisce o null; write lo memorizza; clear lo remove.

const api = new IaGenify({
  apiKey,
  storage: {
    storageType: "custom",          // reported at exchange; informational
    async read()      { return JSON.parse((await redis.get(key)) || "null"); },
    async write(data) { await redis.set(key, JSON.stringify(data)); },
    async clear()     { await redis.del(key); },
  },
});
import json

class RedisSession:
    storage_type = "custom"          # informational
    def read(self): return json.loads(redis.get(key) or "null")
    def write(self, data): redis.set(key, json.dumps(data))
    def clear(self): redis.delete(key)

api = IaGenify(api_key=api_key, storage=RedisSession())
lettura deve restituire null, non lancia

Una prima run non ha nulla memorized. Prende dentro led e restitui null, o la prima chiamata fa fail in lugar di scambiare la chiave.

Un client senza chiude

Se il vostro stoccaggio già tiene una sessione, si può costruire un client senza una chiave. Pass nén e il costruttor renie, nomeando ambele usa.

// Valid: the session comes from the store
const api = new IaGenify({ storage: myStore });

// Refused at construction
new IaGenify({});
// Error: IaGenify requires an API key. Pass { apiKey } or provide a custom
// storage with an existing session.
# Valid: the session comes from the store
api = IaGenify(storage=my_store)

# Refused at construction
IaGenify()
# ValueError: IaGenify requires api_key or a custom session storage.

Mantenendo i locatari separati

const clientFor = (tenant) => new IaGenify({
  apiKey: keyOf(tenant),
  appName: "billing-worker",
  storage: {
    storageType: "custom",
    async read()      { return JSON.parse((await kv.get(`sess:${tenant}`)) || "null"); },
    async write(data) { await kv.put(`sess:${tenant}`, JSON.stringify(data)); },
    async clear()     { await kv.delete(`sess:${tenant}`); },
  },
});
import json

class TenantSession:
    def __init__(self, tenant): self.key = f"sess:{tenant}"
    def read(self): return json.loads(kv.get(self.key) or "null")
    def write(self, data): kv.set(self.key, json.dumps(data))
    def clear(self): kv.delete(self.key)

def client_for(tenant):
    return IaGenify(api_key=key_of(tenant), app_name="billing-worker", storage=TenantSession(tenant))