集成指南
帮助
你可以从浏览器、前端或后端直接使用 hashavatar.app。每个头像 URL 都是确定性的,因此相同的标识符和选项始终会产生相同结果。
基础 URL
当你需要简单的公开图片 URL 时,请使用查询端点。
https://hashavatar.app/v1/[email protected]&algorithm=sha512&kind=robot&background=white&accessory=glasses&color=gold&expression=happy&shape=circle&format=webp&size=256
路径式 URL
如果你更喜欢更整洁的嵌入 URL,可以使用路径形式。
https://hashavatar.app/avatar/fox/[email protected]/webp
HTML 示例
<img
src="https://hashavatar.app/v1/[email protected]&algorithm=sha512&kind=monster&background=themed&accessory=horns&color=crimson&expression=grumpy&shape=hexagon&format=webp&size=256"
alt="Generated monster avatar"
/>
JavaScript 示例
const avatarUrl = new URL("https://hashavatar.app/v1/avatar");
avatarUrl.search = new URLSearchParams({
id: user.email,
algorithm: "sha512",
kind: "robot",
background: "white",
accessory: "glasses",
color: "gold",
expression: "happy",
shape: "circle",
format: "webp",
size: "256",
}).toString();
支持的参数
id: any stable identifier such as an email, username, internal user id, or one-way hashtenant: optional namespace partition for multi-tenant appsstyle_version: optional style namespace such asv2algorithm: identity hash mode; onlysha512is supportedkind: any public hashavatar family, includingcat,dog,robot,planet,rocket,frog,panda,cupcake,pizza,octopus,knight,bear,penguin,dragon,ninja,astronaut,diamond,coffee-cup, andshieldbackground:themed,white,black,dark,light,transparent,polka-dot,striped,checkerboard,grid,sunrise,ocean, orstarryaccessory:none,glasses,hat,headphones,crown,bowtie,eyepatch,scarf,halo, orhornscolor:default,neon-mint,pastel-pink,crimson,gold, ordeep-sea-blueexpression:default,happy,grumpy,surprised,sleepy,winking,cool, orcryingshape:square,circle,squircle,hexagon, oroctagonformat: output format; onlywebpis supportedsize: from64up to1024
配饰和表情图层适用于角色风格的家族。planet、rocket、paws、mushroom、cactus、cupcake、pizza、icecream、diamond、coffee-cup 和 shield 等物体风格家族会被规范化为 accessory=none 和 expression=default。
签名存储链接
如果此部署配置了对象存储,可以从 /v1/avatar/link 请求预签名存储链接。该端点会存储生成的对象,并返回包含签名 URL、对象键和哈希缓存键的 JSON。标准头像响应不会在响应头中暴露签名链接元数据。
GET https://hashavatar.app/v1/avatar/[email protected]&algorithm=sha512&kind=robot&background=white&accessory=glasses&color=gold&expression=happy&shape=circle&format=webp&size=256