MCPcopy Create free account
hub / github.com/AgentOps-AI/agentops / events

Function events

app/api/agentops/api/routes/v1.py:165–252  ·  view source on GitHub ↗
(request: Request, supabase: AsyncSupabaseClient)

Source from the content-addressed store, hash-verified

163
164@router.post("/events")
165async def events(request: Request, supabase: AsyncSupabaseClient):
166 try:
167 api_key = request.headers.get("X-Agentops-Auth")
168
169 sessions, data = await asyncio.gather(
170 supabase.table("sessions").select("id").eq("api_key", api_key).limit(1).single().execute(),
171 request.json(),
172 )
173 # premium_status = await get_premium_status(supabase, sessions['id'])
174 premium_status = False
175
176 session_id = data.get("session_id")
177 session_ids_for_project = [session["id"] for session in sessions]
178 if session_id not in session_ids_for_project:
179 raise RuntimeError("Invalid API Key for session")
180
181 except RuntimeError as e:
182 message = {"message": f"/events: Error posting event: {e}"}
183 logger.error(message)
184 return JSONResponse(message, status_code=401)
185
186 except InvalidModelError as e:
187 message = {"message": f"/events: Invalid model while posting event: {e}"}
188 return JSONResponse(message, status_code=401)
189
190 try:
191 actions = []
192 llms = []
193 tools = []
194 errors = []
195 additional_cost: Decimal | None = Decimal(0)
196 additional_events = 0
197 additional_prompt_tokens = 0
198 additional_completion_tokens = 0
199 for event in data.get("events"):
200 additional_events += 1
201 if event["event_type"] == "llms":
202 llm = await event_handlers.handle_llms(event, premium_status, session_id)
203 cost = llm.get("cost")
204 if cost is not None:
205 additional_cost += Decimal(cost)
206 additional_prompt_tokens += llm["prompt_tokens"]
207 additional_completion_tokens += llm["completion_tokens"]
208 llms.append(llm)
209 elif event["event_type"] == "tools":
210 tools.append(await event_handlers.handle_tools(event, session_id))
211 # TODO: move into an /errors endpoint?
212 elif event["event_type"] == "errors":
213 errors.append(await event_handlers.handle_errors(event, session_id))
214 else:
215 actions.append(await event_handlers.handle_actions(event, session_id))
216
217 if additional_cost == Decimal(0):
218 additional_cost = None
219
220 inserts = []
221 if len(actions) != 0:
222 inserts.append(supabase.table("actions").upsert(actions).execute())

Callers

nothing calls this directly

Calls 5

update_statsFunction · 0.90
jsonMethod · 0.80
upsertMethod · 0.80
getMethod · 0.45
selectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…