Skip to content

API Connection

Dendrite can optionally load persona config from an AgentLayerZero API instead of inline configuration. This enables "embed my AI persona on any website" use cases.

How It Works

  1. Your app calls fetchPersonaConfig(apiUrl, username, slug)
  2. Dendrite fetches the instance settings + personality docs from the API
  3. The response is cached in localStorage (1 hour TTL)
  4. Config is passed to createNeuron()
  5. After init, everything runs locally — no server during chat

Usage

Manual Fetch

ts
import { createNeuron, fetchPersonaConfig } from '@agent-layer-zero/dendrite'

const persona = await fetchPersonaConfig(
  'https://synapse-xxr0cw.fly.dev',
  'shyaboi',
  'career-coach'
)

const neuron = createNeuron({
  modelId: persona.instance.model_id || 'gemma-2-2b-it-q4f16_1-MLC',
  worker: new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' }),
  personalityDocs: persona.personalityDocs.map(d => ({
    type: d.type,
    content: d.content,
    name: d.name,
    order: d.order,
    enabled: d.enabled,
  })),
})

What the API Returns

json
{
  "instance": {
    "slug": "career-coach",
    "name": "Career Coach",
    "model_id": "gemma-2-2b-it-q4f16_1-MLC",
    "temperature": 0.3,
    "max_tokens": 2048,
    "zero_shot_prompt": null
  },
  "personality_docs": [
    {
      "name": "Identity",
      "type": "zero-shot",
      "content": "You are a career coach for Ian Sears...",
      "order": 0,
      "enabled": true
    }
  ]
}

Caching

Persona config is cached in localStorage:

VisitBehavior
FirstAPI call → cache → init
Return (< 1 hour)Cache hit → instant init
Return (> 1 hour)Cache hit → init immediately + background refresh
OfflineCache hit → works with stale data

Cache key format: dendrite_persona_{username}_{slug}

API Endpoint

GET {apiUrl}/api/public/instance/{username}/{slug}

No authentication required for public instances. The API returns the instance config and all enabled personality documents.

Part of the AgentLayerZero platform