# List log lines (/docs/api-reference/logs/list-logs)

The API key's environment log, newest first: every API request made with one of its keys (`source: api`), every email event (`email`) and every webhook delivery attempt (`webhook`). Filter by time range (an hour by default, at most 31 days), source, level, type, status, method, route, key, request, resource or free text. Pass the last `id` as `after` to get the next page while `has_more` is true. Reading logs is not itself logged.

`GET https://api.coss.com/v1/logs`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Query parameters

- `from` (string, date-time): Start of the range (inclusive). Defaults to an hour before `to`.
- `to` (string, date-time): End of the range (exclusive). Defaults to now. At most 31 days.
- `source` (string): Only these sources, comma-separated: `api,email,webhook`.
- `level` (string): Only these levels, comma-separated: `warning,error`.
- `type` (string): Only these types, e.g. `email.bounced,email.complained`.
- `status` (string): Only these status codes or classes, e.g. `4xx,503`.
- `method` (string): Only these HTTP methods, e.g. `POST`.
- `route` (string): Only these routes, e.g. `/v1/emails/:id`.
- `api_key_id` (string): Only requests made with these API keys.
- `request_id` (string, at most 64 characters): Only this request's lines.
- `resource_id` (string, at most 64 characters): Only lines about this resource, e.g. an `email_…` id.
- `q` (string, at most 256 characters): Free text, matched against the message, path, ids and recipient.
- `limit` (integer, 1-100): 1-100, default 50.
- `after` (string): Cursor: the `id` of the last line of the previous page.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.logs.list();
```

HTTP:

```sh
curl -X GET "https://api.coss.com/v1/logs" \
  -H "Authorization: Bearer $COSS_API_KEY"
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.logs.list()
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &coss.ListLogsRequest{}
client.Logs.List(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.logs.list
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Logs\Requests\ListLogsRequest;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->logs->list(
    new ListLogsRequest([]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.logs.requests.ListLogsRequest;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.logs().list(
    ListLogsRequest
        .builder()
        .build()
);
```

.NET:

```csharp
using Coss;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Logs.ListAsync(new ListLogsRequest());
```

## Response 200

A page of log lines.

- `object` ("list", required)
- `data` (object[], required)
  - `object` ("log", required)
  - `id` (string, required)
  - `occurred_at` (string, required, date-time): When it happened.
  - `source` ("api" | "email" | "webhook" | "risk" | "smtp" | "sms" | "sign" | "verify" | "forms" | "scheduling", required): `api`: a request to the API. `email`: an email event. `webhook`: a delivery attempt. `risk`: a risk assessment or its feedback. `smtp`: a message submitted to the SMTP relay. `sms`: an SMS event.
  - `level` ("info" | "warning" | "error", required): `error`: 5xx responses, bounces, complaints, failures. `warning`: 4xx responses, delays, suppressions, failed webhook attempts that will be retried. `info`: everything else.
  - `type` (string, required): `api.request`, `webhook.attempt`, `webhook.forward` (an event `coss listen` forwarded), or an email event type such as `email.delivered`.
  - `message` (string, required): A one-line summary.
  - `request_id` (string | null, required): The `X-Request-Id` of the API request this line belongs to.
  - `api_key_id` (string | null, required): The API key that made the request. `null`: not an API request.
  - `method` (string | null, required): The HTTP method. `null`: not an HTTP line.
  - `path` (string | null, required): The request's path. `null`: not an API request.
  - `route` (string | null, required): The matched route, e.g. `/v1/emails/:id`.
  - `status_code` (integer | null, required): The API response status, or the webhook endpoint's response status.
  - `duration_ms` (integer | null, required): How long it took, in milliseconds. `null`: not timed.
  - `client_ip` (string | null, required): The caller's address. `null`: not an API request.
  - `user_agent` (string | null, required): The caller's `User-Agent`. `null`: not sent.
  - `error_code` (string | null, required): The error's `code`. `null`: no error.
  - `resource_type` (string | null, required): What the line is about: `email`, `domain`, `webhook_endpoint`…
  - `resource_id` (string | null, required): The id of what it's about. `null`: nothing in particular.
  - `recipient` (string | null, required): The recipient an email event is about. `null`: none.
  - `attributes` (map of any, required): Details: redacted request and response bodies for API requests (secrets, attachment contents and long strings are never stored), event data for emails and webhooks.
- `has_more` (boolean, required)

Example:

```json
{
  "object": "list",
  "data": [
    {
      "object": "log",
      "id": "log_01k7c8m4q2f3e9v6t5r1n0p8yz",
      "occurred_at": "2026-01-15T09:30:00.000Z",
      "source": "api",
      "level": "info",
      "type": "api.request",
      "message": "POST /v1/emails 202",
      "request_id": "req_01k7c8m4q2f3e9v6t5r1n0p8yz",
      "api_key_id": "key_01k7c8m4q2f3e9v6t5r1n0p8yz",
      "method": "POST",
      "path": "/v1/emails",
      "route": "/v1/emails",
      "status_code": 202,
      "duration_ms": 48,
      "client_ip": "203.0.113.7",
      "user_agent": "coss-node/0.1.0",
      "error_code": null,
      "resource_type": "email",
      "resource_id": "email_01k7c8m4q2f3e9v6t5r1n0p8yz",
      "recipient": null,
      "attributes": {
        "request": {
          "body": {
            "from": "hello@example.com",
            "to": [
              "user@example.com"
            ],
            "subject": "Hi"
          }
        },
        "response": {
          "body": {
            "object": "email",
            "id": "email_01k7c8m4q2f3e9v6t5r1n0p8yz"
          }
        }
      }
    }
  ],
  "has_more": false
}
```

## Errors

- `400`: The `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `422`: A query parameter failed validation (`validation_error`), or the range is empty or longer than 31 days (`invalid_range`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).