# Understanding Source Availability in last30days-skill: Configuration and Diagnostics Guide

> Learn how to master last30days-skill source availability. This guide explains configuration and diagnostics for APIs, keys, and credentials to optimize your content search.

- Repository: [Matt Van Horn/last30days-skill](https://github.com/mvanhorn/last30days-skill)
- Tags: how-to-guide
- Published: 2026-03-25

---

**The last30days-skill determines which content sources (Reddit, X, and Web) are available by inspecting API keys and authentication credentials in [`scripts/lib/env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/lib/env.py), returning a specific availability string—such as `all`, `both`, `reddit-web`, `reddit`, `web`, or `none`—that downstream pipelines use to decide which search modules to execute.**

Understanding source availability in last30days-skill is essential for configuring the research pipeline correctly. The skill dynamically detects which backends—Reddit, X (formerly Twitter), or general web search—are functional based on your credential configuration stored in environment files or shell variables. This detection logic lives in the [`scripts/lib/env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/lib/env.py) module according to the mvanhorn/last30days-skill source code.

## How Source Availability Is Determined

The skill follows a four-step resolution process to determine which sources are usable. Each step maps to specific functions in [`scripts/lib/env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/lib/env.py).

### Step 1: Loading Configuration Files

The `get_config()` function (lines 15-38 of [`env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/env.py)) loads credentials in strict priority order: process environment variables take precedence, followed by the per-project `.claude/last30days.env` file, and finally the global `~/.config/last30days/.env` file. This function also extracts OpenAI/Codex tokens, X-search cookies, and any web-search API keys required for backend initialization.

### Step 2: Detecting Individual Backends

After loading configuration, helper functions check specific credential requirements for each source:

- **Reddit**: The `is_reddit_available()` function (lines 90-98) checks for the presence of `SCRAPECREATORS_API_KEY` or a working OpenAI key.
- **X (Twitter)**: Availability requires either an `XAI_API_KEY` or Bird-installed authentication credentials (validated within `get_missing_keys`).
- **Web Search**: The `has_web_search_keys()` function (lines 31-33) verifies the presence of `OPENROUTER_API_KEY`, `PARALLEL_API_KEY`, or `BRAVE_API_KEY`.

### Step 3: Computing the Availability String

The `get_available_sources(config)` function (lines 14-28) combines these boolean checks into a single string that downstream CLI code consumes. The logic is deliberately permissive: Reddit is always considered *available* because it can fall back to a public JSON endpoint when API keys are absent. The function returns one of six specific values indicating which combination of backends are ready.

### Step 4: Reporting Missing Keys

Finally, `get_missing_keys(config)` (lines 52-76) identifies which credential categories remain unconfigured. This powers the `--diagnose` flag output, explicitly listing whether X authentication or web search keys are absent.

## The Availability String Results

The `get_available_sources()` function returns one of the following enumerated strings:

| Returned value | Meaning |
|----------------|---------|
| `all` | Reddit **and** X **and** a web backend are all configured |
| `both` | Reddit and X are ready, but no web backend |
| `reddit-web` | Reddit **and** a web backend are ready (X missing) |
| `reddit` | Only Reddit is ready |
| `web` | Only a web backend is ready (no Reddit, no X) |
| `none` | No source can be used (no keys at all) |

These strings are consumed by [`scripts/last30days.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/last30days.py) to enable or skip corresponding search modules in the pipeline.

## Running Diagnostics with the --diagnose Flag

The CLI provides a `--diagnose` flag that prints the complete availability report as JSON and exits. This is the definitive method for verifying that your keys are recognized correctly by the detection logic implemented in [`env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/env.py).

```bash
python3 scripts/last30days.py --diagnose

```

Typical output appears as:

```json
{
  "available": "both",
  "missing": "web",
  "config_source": "global:/home/you/.config/last30days/.env",
  "keys": {
    "SCRAPECREATORS_API_KEY": true,
    "XAI_API_KEY": false,
    "PARALLEL_API_KEY": false
  }
}

```

The implementation that prints this JSON payload resides near line 1550 of [`scripts/last30days.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/last30days.py), calling `env.get_config()`, then `env.get_available_sources()` and `env.get_missing_keys()` to construct the diagnostic object.

## Where to Configure API Keys

The skill supports three configuration scopes, loaded with the precedence: Environment Variables > Per-Project > Global.

### Global Configuration

Store persistent credentials in `~/.config/last30days/.env`. This path is defined by the `CONFIG_FILE` constant in [`env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/env.py) and serves as the default fallback when project-specific or environment variables are absent.

### Per-Project Configuration

Place a `.claude/last30days.env` file in your repository root. The `_find_project_env()` function (lines 98-112 of [`env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/env.py)) detects this file and overrides the global configuration. This scope is ideal for maintaining separate credentials across multiple research projects on the same machine or for CI/CD pipelines.

### Environment Variables

Export keys directly in your shell for the highest priority override:

```bash
export XAI_API_KEY="your_key_here"
export PARALLEL_API_KEY="your_key_here"

```

Process environment variables take precedence over all file-based configuration sources.

## Practical Code Examples

### Checking Availability Programmatically

You can inspect source availability from Python scripts by importing the `env` module:

```python
from scripts.lib import env

cfg = env.get_config()               # Load merged configuration

available = env.get_available_sources(cfg)
missing = env.get_missing_keys(cfg)

print(f"Available sources: {available}")
print(f"Missing categories: {missing}")

```

### Using the CLI Diagnostic Output

Capture the JSON diagnostic in shell scripts for automated validation:

```bash
#!/usr/bin/env bash
diagnose_json=$(python3 scripts/last30days.py --diagnose)
echo "$diagnose_json" | jq -r '.available'

```

### Overriding Configuration for Single Runs

Execute the skill with temporary credentials without modifying configuration files:

```bash
XAI_API_KEY=abcd1234 PARALLEL_API_KEY=xyz987 python3 scripts/last30days.py "AI video tools"

```

## Key Implementation Files

| File | Role |
|------|------|
| [`scripts/lib/env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/lib/env.py) | Loads environment files, resolves authentication, and decides which sources are usable via `get_available_sources()` and `get_missing_keys()` |
| [`scripts/last30days.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/last30days.py) | CLI entry point implementing the `--diagnose` flag and orchestrating search pipelines based on the availability string |
| [`tests/test_smoke.py`](https://github.com/mvanhorn/last30days-skill/blob/main/tests/test_smoke.py) | Integration tests validating that the `--diagnose` flag produces well-formed availability JSON |

## Summary

- **Source availability** in last30days-skill is computed in [`scripts/lib/env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/scripts/lib/env.py) by inspecting API keys and Bird authentication status.
- The `get_available_sources()` function returns discrete strings (`all`, `both`, `reddit-web`, `reddit`, `web`, `none`) indicating which backends are operational.
- Use `python3 scripts/last30days.py --diagnose` to verify your configuration via JSON output.
- Configuration follows a hierarchy: process environment variables override per-project `.claude/last30days.env`, which overrides the global `~/.config/last30days/.env`.

## Frequently Asked Questions

### What API keys are required for Reddit source availability?

Reddit requires either a `SCRAPECREATORS_API_KEY` or a working OpenAI key to be considered fully available via `is_reddit_available()`. However, the skill treats Reddit as always available in `get_available_sources()` because it can fall back to a public JSON endpoint when no keys are present.

### How does last30days-skill handle missing X authentication?

The skill checks for `XAI_API_KEY` or Bird-installed authentication in `get_missing_keys()`. If neither is present, X is excluded from the availability string, and the `--diagnose` output will list X as a missing category.

### Can I use the skill with only web search enabled?

Yes. If you configure `OPENROUTER_API_KEY`, `PARALLEL_API_KEY`, or `BRAVE_API_KEY` while omitting Reddit and X credentials, `get_available_sources()` returns `"web"`. The pipeline will execute web searches while skipping social media backends.

### Where should I store API keys for CI/CD pipelines?

Store credentials in a per-project `.claude/last30days.env` file within your repository or inject them as environment variables in your CI configuration. The per-project file approach avoids conflicts with other projects on shared runners, as detected by `_find_project_env()` in [`env.py`](https://github.com/mvanhorn/last30days-skill/blob/main/env.py).