Skip to content

Import from Portkey

Do the shared setup first: an ingest key, pip install metergraphrelay, and a .env holding METERGRAPH_APP_TOKEN.

Portkey is the one source with two routes in, and which one you take depends on your Portkey plan.

Export fileLogs Export API
What it needsA JSONL log export you download yourselfA Portkey key with the logs.export scope, an Enterprise feature
Contacts PortkeyNoYes
Runs on a scheduleNoYes, hourly from cron
Deduplicates re-read rowsNoYes

Both are spelled metergraphrelay sync portkey. Passing a file selects the export path. Omitting one selects the API path. There is no metergraphrelay pull portkey.

Download a JSONL log export from Portkey, then convert and upload it. This never contacts Portkey and needs no Portkey credential.

  1. Use Portkey’s own log export. You need a Portkey subscription with log export enabled.

  2. metergraphrelay sync portkey export.jsonl

    With no --output the converted file is a private temporary file, removed after the upload. Pass --output to keep it, including when the upload fails:

    metergraphrelay sync portkey export.jsonl --output converted.jsonl
    metergraphrelay push converted.jsonl # retry the upload on its own

    The command prints one line: how many rows it converted, how many it skipped, how many it pushed, and how many failed.

--source-scope, --initial-since and --max-window-seconds belong to the API path. Passing one alongside a file is an error rather than a silent no-op.

With a Portkey key carrying the logs.export scope, the relay pulls windows itself and can run from cron.

.env
METERGRAPH_APP_TOKEN=<your ingest key>
PORTKEY_API_KEY=<a key with the logs.export scope>
# PORTKEY_WORKSPACE=ws-acme # or pass --source-scope on every run
# PORTKEY_BASE_URL=https://api.portkey.ai/v1
metergraphrelay sync portkey --source-scope ws-acme --initial-since 2026-08-01T00:00:00Z

--source-scope is the Portkey workspace id. It is not a secret, and it is also what names the checkpoint on the Metergraph side, so it must never change. It falls back to PORTKEY_WORKSPACE. One Portkey workspace maps to one Metergraph workspace.

--output belongs to the export-file path, and passing it here is an error.

The window, overlap, lease and exit code contract is the same as every other source: see How ongoing sync works.

FieldWhere it comes from
RouteThe workflow_name in the request’s Portkey metadata. Without one, portkey/backfill
TimestampThe request’s created_at, kept as the original. A row whose timestamp cannot be read fails the conversion rather than being re-dated
ProviderThe log’s ai_org
ModelThe log’s ai_model
Input and output tokensThe log’s req_units and res_units
CostThe log’s cost, converted from cents to dollars
LatencyThe log’s response_time
Statuserror when the response status code is 400 or above, or missing
Error typeThe response’s error message
ContentThe request and response from the export, copied verbatim
Tool calls and tool namesExtracted from the response
Trace and spanThe log’s trace_id and its own id
TagsThe whole Portkey metadata object
  • Cache and reasoning token buckets. Portkey logs carry a request and a response unit count and nothing finer, so those columns stay empty.
  • Environment. Portkey rows arrive with no environment set, so they fall outside any environment filter in the dashboard.
  • Function attribution, streaming detail, outcomes and repository identity, as on every import path.
  • A --route override. Neither Portkey path accepts one. If the route matters, set workflow_name in the Portkey metadata at the source.
SymptomLikely causeWhat to do
API mode is rejected at authorizationThe key lacks logs.export, an Enterprise scopeUse the export-file path
--source-scope ... only valid in Portkey API cron modeAn API flag was passed alongside a fileDrop the flag, or drop the file
--output is only valid with a local EXPORT_FILE--output was passed in API modeDrop it
source scope not setNeither --source-scope nor PORTKEY_WORKSPACE is setSet one to the workspace id
A window keeps failing on one rowA row the ingest API refusesFix the row at the source. The window will not advance past it
Every route is portkey/backfillThe requests carry no workflow_name metadataSet it in Portkey