Skip to main content 홈 크리에이터 comeonoliver skillshub cohere-webhooks-events
cohere-webhooks-events Implement Cohere streaming event handling, SSE patterns, and connector webhooks.
Use when building streaming UIs, handling chat/tool events,
or registering Cohere connectors for RAG.
Trigger with phrases like "cohere streaming", "cohere events",
"cohere SSE", "cohere connectors", "cohere webhook".
설치로 이동 Skills Marketplace 커뮤니티가 만든 AI 스킬을 발견하고 탐색하세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/ComeOnOliver/skillshub --skill cohere-webhooks-events명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
Zip 다운로드 다운로드 중... 이 저장소의 다른 Skills Review product and feature risk before an AI coding agent starts implementation.
Use Xquik for X data and confirmation-gated X actions: tweet search, user lookup, follower export, media download, monitors, webhooks, MCP, and SDK workflows.
Canton Network open-source ecosystem guide covering DAML SDK, Canton runtime, and Splice applications. Use when working with Canton Network, DAML smart contracts, or building decentralized applications.
name cohere-webhooks-events description Implement Cohere streaming event handling, SSE patterns, and connector webhooks.
Use when building streaming UIs, handling chat/tool events,
or registering Cohere connectors for RAG.
Trigger with phrases like "cohere streaming", "cohere events",
"cohere SSE", "cohere connectors", "cohere webhook".
allowed-tools Read, Write, Edit, Bash(curl:*) version 1.0.0 license MIT author Jeremy Longshore <jeremy@intentsolutions.io> tags ["saas","ai","nlp","cohere"] compatible-with claude-code
Cohere Streaming Events & Connectors
Overview
Handle Cohere's streaming chat events (SSE), tool-call events, citation events, and register data connectors for RAG. Cohere does not use traditional webhooks — its event model is streaming-based.
Prerequisites
cohere-ai SDK v7+
Understanding of Server-Sent Events (SSE)
For connectors: HTTPS endpoint accessible from internet
Instructions
Step 1: Chat Streaming Events
Cohere's chatStream returns a stream of typed events:
import { CohereClientV2 } from 'cohere-ai' ;
const cohere = new CohereClientV2 ();
async function handleStream (userMessage : string ) {
const stream = await cohere.chatStream ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : userMessage }],
});
for await (const event of stream) {
switch (event.type ) {
case 'content-start' :
console .log ('--- Generation started ---' );
break ;
case 'content-delta' :
const text = event.delta ?. ?. ?. ?? ;
process. . (text);
;
:
. ( );
;
:
. ( , event. ?. ?. );
;
:
. ( , event. ?. ?. ?. ?. );
;
:
;
:
. ( );
;
:
. ( , event. );
;
:
. ( , event. ?. );
. ( , event. ?. );
;
}
}
}
message
content
text
''
stdout
write
break
case
'content-end'
console
log
'\n--- Generation complete ---'
break
case
'citation-start'
console
log
'Citation:'
delta
message
citations
break
case
'tool-call-start'
console
log
'Tool call started:'
delta
message
toolCalls
function
name
break
case
'tool-call-delta'
break
case
'tool-call-end'
console
log
'Tool call complete'
break
case
'message-start'
console
log
'Message ID:'
id
break
case
'message-end'
console
log
'Finish reason:'
delta
finishReason
console
log
'Usage:'
delta
usage
break
Step 2: RAG Streaming with Citations async function streamRAG (query : string , docs : string [] ) {
const stream = await cohere.chatStream ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : query }],
documents : docs.map ((text, i ) => ({
id : `doc-${i} ` ,
data : { text },
})),
});
let fullText = '' ;
const citations : Array <{ start : number ; end : number ; text : string ; sources : string [] }> = [];
for await (const event of stream) {
if (event.type === 'content-delta' ) {
const chunk = event.delta ?.message ?.content ?.text ?? '' ;
fullText += chunk;
process.stdout .write (chunk);
}
if (event.type === 'citation-start' ) {
const cite = event.delta ?.message ?.citations ;
if (cite) {
citations.push ({
start : cite.start ,
end : cite.end ,
text : cite.text ,
sources : cite.sources ?.map ((s : any ) => s.id ) ?? [],
});
}
}
}
return { fullText, citations };
}
Step 3: Streaming Tool Use const tools = [{
type : 'function' as const ,
function : {
name : 'get_price' ,
description : 'Get stock price' ,
parameters : {
type : 'object' as const ,
properties : { ticker : { type : 'string' } },
required : ['ticker' ],
},
},
}];
async function streamToolUse (query : string ) {
const stream = await cohere.chatStream ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : query }],
tools,
});
let currentToolName = '' ;
let currentToolArgs = '' ;
for await (const event of stream) {
switch (event.type ) {
case 'tool-call-start' :
currentToolName = event.delta ?.message ?.toolCalls ?.function ?.name ?? '' ;
currentToolArgs = '' ;
console .log (`Calling tool: ${currentToolName} ` );
break ;
case 'tool-call-delta' :
currentToolArgs += event.delta ?.message ?.toolCalls ?.function ?.arguments ?? '' ;
break ;
case 'tool-call-end' :
console .log (`Tool args: ${currentToolArgs} ` );
break ;
case 'content-delta' :
process.stdout .write (event.delta ?.message ?.content ?.text ?? '' );
break ;
}
}
}
Step 4: SSE Endpoint for Frontend
import express from 'express' ;
const app = express ();
app.use (express.json ());
app.post ('/api/chat/stream' , async (req, res) => {
res.setHeader ('Content-Type' , 'text/event-stream' );
res.setHeader ('Cache-Control' , 'no-cache' );
res.setHeader ('Connection' , 'keep-alive' );
const cohere = new CohereClientV2 ();
try {
const stream = await cohere.chatStream ({
model : 'command-a-03-2025' ,
messages : req.body .messages ,
});
for await (const event of stream) {
if (event.type === 'content-delta' ) {
const text = event.delta ?.message ?.content ?.text ?? '' ;
res.write (`data: ${JSON .stringify({ type : 'text' , text })} \n\n` );
}
if (event.type === 'citation-start' ) {
res.write (`data: ${JSON .stringify({ type : 'citation' , data: event.delta })} \n\n` );
}
if (event.type === 'message-end' ) {
res.write (`data: ${JSON .stringify({ type : 'done' , usage: event.delta?.usage })} \n\n` );
}
}
res.write ('data: [DONE]\n\n' );
res.end ();
} catch (err) {
res.write (`data: ${JSON .stringify({ type : 'error' , message: String (err) })} \n\n` );
res.end ();
}
});
Step 5: Cohere Connectors (Data Source Registration)
const connector = await cohere.connectors .create ({
name : 'internal-docs' ,
url : 'https://api.yourapp.com/search' ,
description : 'Internal documentation search' ,
});
const response = await cohere.chat ({
model : 'command-a-03-2025' ,
messages : [{ role : 'user' , content : 'How do I reset my password?' }],
connectors : [{ id : connector.connector .id }],
});
const connectors = await cohere.connectors .list ();
console .log ('Registered connectors:' , connectors.connectors .length );
Connector endpoint contract: Your URL receives POST { query: string } and must return { results: [{ id, text, title?, url? }] }.
Event Type Reference Event When Contains message-startStream begins Message ID content-startText generation starts Content index content-deltaEach text token Text chunk content-endText generation ends - citation-startCitation found Source, position tool-call-startTool call begins Tool name tool-call-deltaTool args streaming Argument chunk tool-call-endTool call complete - message-endStream ends Finish reason, usage
Error Handling Issue Cause Solution Stream drops mid-response Network timeout Set higher timeout, add reconnect No citation events No documents passed Include documents param Tool events but no content Tool call in progress Wait for tool results, re-stream Connector returns empty Bad search endpoint Test endpoint with curl
Resources
Next Steps For performance optimization, see cohere-performance-tuning.