# Authentication & Mind Key SUMMARY: วิธีที่ Synapse authentication ทำงาน: Mind Key สำหรับ agent, JWT สำหรับ human, ?key= ปิดใช้งานโดยค่าเริ่มต้น (Bearer เท่านั้น, AUTH_QUERY_KEY_MODE=deny) KEY CONTEXT: Two auth methods: Mind Key (token-scoped, never expires) and JWT (user-scoped, 7-day expiry). Mind Key: Authorization: Bearer mk_xxx (?key= DISABLED by default — AUTH_QUERY_KEY_MODE=deny hardened default; 401 + hint on ?key=) JWT: Authorization: Bearer eyJ... (120 req/min external IPs, unlimited internal; used for /register, /login, /minds, /sharing) Mind Key is shown only once at creation. Store it permanently. Each mind has exactly one Mind Key. Multiple minds = multiple keys. Authentication & Mind Key Synapse ใช้สองวิธี authentication แต่ละวิธีปรับให้เหมาะกับกรณีใช้งานต่างกัน การเข้าใจความแตกต่างเป็นสิ่งจำเป็นสำหรับการสร้าง integration ที่เชื่อถือได้ สองวิธี Auth | วิธี | กรณีใช้งาน | Rate Limit | Expiry | |--------|----------|------------|--------| | Mind Key | LLM agent, เครื่องมืออัตโนมัติ | 120 ต่อนาที (Bearer ภายนอก); ?key= ปิดใช้งานโดยค่าเริ่มต้น (deny) | ไม่มี | | JWT | Human-facing UI, การดำเนินการบัญชี | 120/นาที (IP ภายนอก) | 7 วัน | Mind Key (สำหรับ Agent) Mind Key เป็น tenant-scoped API token ใช้ยืนยันตัวตนข้อมูล mind เดียว (memory, task, chat, script ฯลฯ) ใช้สำหรับ: - LLM agent เรียก API - สคริปต์ automation เบื้องหลัง - การกำหนดค่า MCP server - integration ที่อยู่ยาวนานใด ๆ Header authentication (แนะนำ) [CODE BLOCK] Query parameter (ปิดใช้งานโดยค่าเริ่มต้น) [CODE BLOCK] > [!WARNING] > query parameter ถูกปิดใช้งานโดยค่าเริ่มต้นที่เสริมความปลอดภัย : > เซิร์ฟเวอร์ตอบกลับ ด้วย 401 และคำแนะนำ "Query-param auth (?key=) is disabled" Bearer เท่านั้นคือค่าเริ่มต้นที่ปลอดภัย > (SSOT: ) จะใช้ เป็นวาล์วชั่วคราวที่ 60 req/min (ต่อ IP) ได้เฉพาะเมื่อผู้ดูแล > ตั้ง อย่างชัดเจน ไคลเอนต์ Bearer ภายนอกได้ 120 req/min ต่อเอกลักษณ์; > เครือข่ายภายในที่เชื่อถือได้ไม่จำกัด ใช้ header เมื่อใดก็ตามที่ client ของคุณรองรับ custom header การสร้าง Mind Key [CODE BLOCK] Response รวม — บันทึกทันที แสดงเพียงครั้งเดียว รายการ mind ของคุณ [CODE BLOCK] ลบ mind (ย้อนกลับไม่ได้!) [CODE BLOCK] JWT (สำหรับ Human) JWT ยืนยันตัวตน บัญชีผู้ใช้ ไม่ใช่ mind เฉพาะ ใช้สำหรับ: - การสมัครและล็อกอินบัญชี - สร้าง / รายการ / ลบ mind - แชร์ mind กับผู้ใช้อื่น - การจัดการ Web Push subscription สมัคร [CODE BLOCK] ส่งกลับ: ล็อกอิน [CODE BLOCK] ส่งกลับ: การหมดอายุของ JWT JWT หมดอายุหลัง 7 วัน เมื่อ JWT หมดอายุ เพียงเรียก อีกครั้งเพื่อรับใหม่ Mind Key ไม่หมดอายุ ดังนั้น integration ของ agent ที่มีอยู่ยังทำงานต่อ แนวทางปฏิบัติด้านความปลอดภัย > [!CRITICAL] > - อย่า commit Mind Key ลง git ใช้ environment variable > - อย่า log Mind Key ปิดบังใน log () > - หมุนเวียน key หากคุณสงสัยว่ารั่ว (ลบ mind, สร้างใหม่) > - ใช้หนึ่ง mind ต่อโปรเจกต์ เพื่อจำกัดผลกระทบหาก key รั่ว รูปแบบ environment variable [CODE BLOCK] [CODE BLOCK] กำหนดค่า MCP server [CODE BLOCK] รูปแบบ Multi-Mind ผู้ใช้แต่ละคนสามารถมีหลาย mind รูปแบบทั่วไป: | ชื่อ Mind | วัตถุประสงค์ | |-----------|---------| | | memory เกี่ยวกับงาน | | | ค่ากำหนดส่วนตัว, ครอบครัว | | | context โปรเจกต์เฉพาะ | | | ความคืบหน้าการเรียนรู้ | | | fallback สำหรับใช้ทั่วไป | ใช้ Mind Key ต่างกันสำหรับ LLM session ต่างกันเพื่อแยก context Rate Limit | วิธี Auth | Limit | Scope | |-------------|-------|-------| | Mind Key (header) | 120/นาที จาก IP ภายนอก (ต่อหนึ่งตัวตน); ไม่จำกัดสำหรับเครือข่ายภายในที่เชื่อถือได้ | Per-mind | | Mind Key (?key=, เฉพาะเมื่อ allow) | 60/min | Per-IP | | JWT (header) | 120 req/นาที (IP ภายนอก; ไม่จำกัดสำหรับเครือข่ายภายในที่เชื่อถือได้) | Per-user | | Public endpoint | None | Global | Rate limit header (, , ) รวมอยู่ใน response เมื่อเกี่ยวข้อง ขั้นตอนถัดไป - Mind Key vs JWT — เมื่อใช้อันไหน - Memory API — สิ่งที่คุณทำได้กับ Mind Key - User API — การจัดการบัญชีด้วย JWT