Welcome to Portkey Forum

Updated yesterday

I need clarification on how to structure the metadata to get information about each trace_id when using the Get Metadata Grouped Data API.

Hey @Vrushank | Portkey ,
I’m currently working with the "Get Metadata Grouped Data" API (https://api.portkey.ai/v1/analytics/groups/metadata/{metadataKey}) to retrieve pricing data for analytics. I’ve referred to the documentation, but I need some clarification on how to structure the metadata to get information about each trace_id.

Could you please help me understand:

What specific metadata key-value pairs need to be passed in the metadata parameter to retrieve data grouped by trace_id?
Is there a way to filter or group the results specifically by trace_id using this endpoint?
Any guidance or examples would be greatly appreciated!
V
G
C
24 comments
Hey @Chaitanya, welcome! So trace_id is a param completely separate from the metadata. You can pass trace_id for any request just with the trace_id param, and it is through this filter on the analytics API that you can retrieve it
@Chaitanya what's your org on Portkey?
Hey, are you looking for a tree like visaulization?

You can do nesting using the API, just pass the parent traceId and the child is spanId
to do further nesting you can send parent_span_id
Are there any other API's exposed to get the analytics data about cost and token without time_of_generation_min and time_of_generation_max parameters?
@Chaitanya what exact data are you looking for? I can check
Also, can you share your org id on Portkey?
Hi @Vrushank | Portkey , Thank you for your reply. I need data about "cost incurred" and "tokens used".
Sure, org_id is "UnityWealth.ai"
Also I am trying to get Get Metadata Grouped Data
Plain Text
curl --request GET \
  --url 'https://api.portkey.ai/v1/analytics/groups/metadata/log_level?trace_id=*************&time_of_generation_min=2024-12-24T22%3A30%3A58%2B05%3A30&time_of_generation_max=2024-12-24T22%3A31%3A00%2B05%3A3' \
  --header 'x-portkey-api-key: **********'

But getting this response
Plain Text
{
  "success": false,
  "data": {
    "message": "You do not have enough permissions to execute this request",
    "errorCode": "AB03",
    "request_id": "3f5c4737-432b-4710-ac7d-085081df718e"
  }
}

The api key passed contains all the permissions
I tried with a service level key and user level key with all the permissions, still getting the same response
Hi @Vrushank | Portkey @Griphook | Portkey
I'm experiencing a permissions issue while trying to access the "Get Metadata Grouped Data" API endpoint. Here are the details:

Details
Organization ID: UnityWealth.ai
Request ID: 3f5c4737-432b-4710-ac7d-085081df718e
Error Code: AB03
Endpoint: https://api.portkey.ai/v1/analytics/groups/metadata/user

Issue Description:
I'm receiving a "You do not have enough permissions to execute this request" error
I've tried using both service-level and user-level API keys with all permissions enabled
The error persists regardless of the API key type used

API Request Details:
Method: GET
Parameters include trace_id, time_of_generation_min, and time_of_generation_max
All API keys used have been verified to have the necessary permissions

What I'm Trying to Achieve:
Retrieve analytics data grouped by metadata
to Access information about cost incurred and tokens used
Group results by metadatakey user
Filter results by trace_id

Could you please:
Verify if there are any organization-level restrictions affecting this access
Confirm the specific permissions required for this endpoint
Provide guidance on the correct way to access this data

Thank you for your assistance.
@Chaitanya the analytics API is still in beta, @Vrushank | Portkey can enable it for you depending on your usecase
Hi @Griphook | Portkey, Thank you for the clarification!
@Vrushank | Portkey If you could you please enable the analytics API for my organization, that would be great. Let me know if you need any additional details from my side to proceed. Looking forward to your confirmation.
Doing this now - will let you know if/when you can access the API!
Hi @Chaitanya done now. Can you try making another request?
@Vrushank | Portkey Thank you so much for enabling the APIs! Just tried making a request, and it worked perfectly. Really appreciate your quick support.
Hey @Vrushank | Portkey , I am trying to fetch cost data using trace_id and span_id
Plain Text
import requests

url = "https://api.portkey.ai/v1/analytics/graphs/cost"

querystring = {"span_id":"ed4e4236-96dd-448d-8b74-84a9302ac7d7","trace_id":"1736937711069"}

headers = {"x-portkey-api-key": "[REDACTED]"}

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)


As you can see I am getting a response with incorrect costs (zero), which to me means span_id is not being aggregated correctly or factored in this operation. I have attached the exact redacted log of the query with this span_id as well for evidence.

Plain Text
{
  "summary": {
    "total": 0,
    "avg": 0
  },
  "data_points": [
    {
      "timestamp": "2025-01-15T00:00:00.000Z",
      "total": 0,
      "avg": 0
    }
  ],
  "is_quota_exceeded": false,
  "object": "analytics-graph"
}
Can you please confirm this bug, and advise an eta for the fix ?
Or let me know If I need to raise this separately ..
What is the underlying model for this span? It's possible that we do not have the pricing config updated for that model too
I've shared this with the team regardless and we'll let you know the ETA here shortly if it's a bug
Add a reply
Sign up and join the conversation on Discord