Generation Usage Logs

    Query generation usage records associated with the current API Key.

    GET/api/v1/generations/logs
    FieldValue
    Base URLhttps://api.gate.ai
    AuthAuthorization: Bearer <API_KEY>
    FormatGate.AI REST JSON
    Rate limit1 request per second per API Key

    Query all records for a specific trace_id, or retrieve the 100 most recent records for the current API Key.

    • Query by Trace: Include a valid trace_id to return all exact matches owned by the current API Key, ordered by id DESC .
    • Query recent records: Omit the request body, send an empty body, or send {} to return the 100 most recent records for the current API Key, ordered by created_at DESC, id DESC .
    • If the Trace does not exist, its logs have not been generated, or it does not belong to the current API Key, the API returns HTTP 200 with an empty array.

    Request Parameters

    NameInTypeRequiredDescription
    AuthorizationheaderstringYesAPI Key authentication in the format: Bearer <API_KEY>
    Content-TypeheaderstringYesMust be application/json

    Request Body

    NameTypeRequiredDescription
    trace_idstringNoExact, case-sensitive Trace ID. Must be 1 to 128 characters.

    Example: query by Trace

    bash
    1curl -X POST 'https://api.gate.ai/api/v1/generations/logs' \2  -H 'Authorization: Bearer <API_KEY>' \3  -H 'Content-Type: application/json' \4  -d '{"trace_id":"Trace-AbC-123"}'

    Example: query the 100 most recent records

    bash
    1curl -X POST 'https://api.gate.ai/api/v1/generations/logs' \2  -H 'Authorization: Bearer <API_KEY>' \3  -H 'Content-Type: application/json' \4  -d '{}'

    Response Fields

    NameTypeDescription
    codeintegerBusiness status code. Success is always 200.
    msgstringStatus description. Success is always success.
    timestampstringCurrent server Unix timestamp in seconds.
    dataarrayUsage log array; an empty array when no records match.
    data[].idintegerUsage record ID.
    data[].trace_idstringRequest Trace ID.
    data[].span_idstringRequest Span ID.
    data[].session_idstringSession ID.
    data[].api_key_idstringID of the API Key that generated the record.
    data[].user_idstringUser ID.
    data[].appstringCalling application identifier.
    data[].standard_modelstringStandard model name.
    data[].usage_modelstringModel name actually used for metering.
    data[].streambooleanWhether the original request used streaming.
    data[].response_statusintegerHTTP response status of the original request.
    data[].latencyintegerOriginal request latency in milliseconds.
    data[].input_tokensintegerNumber of input tokens.
    data[].output_tokensintegerNumber of output tokens.
    data[].total_tokensintegerTotal token count.
    data[].cache_read_tokensintegerNumber of cache-read tokens.
    data[].cache_write_tokensintegerNumber of cache-write tokens.
    data[].input_tokens_detailsstringInput token details in the stored string format.
    data[].output_tokens_detailsstringOutput token details in the stored string format.
    data[].input_coststringInput cost as a decimal string.
    data[].output_coststringOutput cost as a decimal string.
    data[].cache_read_coststringCache-read cost as a decimal string.
    data[].cache_write_coststringCache-write cost as a decimal string.
    data[].total_coststringTotal cost as a decimal string.
    data[].is_freebooleanWhether this request was covered by free quota.
    data[].timestampstringUsage time in ISO 8601 UTC.
    data[].created_atstringRecord creation time in ISO 8601 UTC.
    data[].metadatastringExtended call information in the stored string format.

    Response Example

    json
    1{2  "code": 200,3  "msg": "success",4  "timestamp": "1784633852",5  "data": [6    {7      "id": 42,8      "trace_id": "Trace-AbC-123",9      "span_id": "span-001",10      "session_id": "session-001",11      "api_key_id": "1001",12      "user_id": "2002",13      "app": "example-client",14      "standard_model": "openai/gpt-5",15      "usage_model": "gpt-5",16      "stream": false,17      "response_status": 200,18      "latency": 842,19      "input_tokens": 120,20      "output_tokens": 80,21      "total_tokens": 200,22      "cache_read_tokens": 20,23      "cache_write_tokens": 0,24      "input_tokens_details": "{"cached_tokens":20}",25      "output_tokens_details": "{"reasoning_tokens":10}",26      "input_cost": "0.00120000",27      "output_cost": "0.00160000",28      "cache_read_cost": "0.00002000",29      "cache_write_cost": "0.00000000",30      "total_cost": "0.00282000",31      "is_free": false,32      "timestamp": "2026-07-21T08:30:00Z",33      "created_at": "2026-07-21T08:30:01Z",34      "metadata": "{"request_type":"audio"}"35    }36  ]37}

    No matching records

    json
    1{2  "code": 200,3  "msg": "success",4  "timestamp": "1784633852",5  "data": []6}

    Response

    StatusMeaningDescriptionSchema
    200OKQuery succeeded; data is an empty array when no records match.UsageLogResponse
    400Bad RequestInvalid JSON body, or invalid trace_id type or length.ErrorResponse
    401UnauthorizedThe API Key is missing, invalid, expired, revoked, disabled, or inactive.ErrorResponse
    403ForbiddenReserved for future API Key permission policies.ErrorResponse
    429Too Many RequestsThe API Key exceeded 1 request per second; the response includes Retry-After.ErrorResponse
    500Internal Server ErrorDatabase query failure or internal gateway error.ErrorResponse

    Error Response Example

    json
    1{2  "error": {3    "type": "invalid_request_error",4    "message": "invalid API key"5  }6}