Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:0xranx OpenContext AI API

From Leeroopedia
Knowledge Sources
Domains AI, Chat
Last Updated 2026-10-24 10:00 GMT

Overview

OpenAI-compatible AI chat API access for generating AI reflections on idea journal entries, supporting OpenAI and Ollama providers.

Description

This environment provides access to an OpenAI-compatible chat completion API for the idea journaling reflection feature. The default provider is `openai` with model `gpt-4o`, but it also supports `ollama` for local AI inference. The API key, base URL, model, and custom system prompt are configurable. When using Ollama, no API key is required.

Usage

Use this environment for AI-powered reflection generation on idea journal entries. It is the mandatory prerequisite for the `AIContext_generateReflection` implementation which streams AI responses to the user.

System Requirements

Category Requirement Notes
OS Any API is accessed via HTTP
Hardware Any Network access for OpenAI; local GPU for Ollama
Network Internet (OpenAI) or localhost (Ollama) Depends on provider

Dependencies =

npm Packages

  • `openai` >= 6.13.0

Runtime

  • OpenAI API access (cloud) or Ollama running locally

Credentials

  • `AI_API_KEY` — API key for AI chat service (OpenAI-compatible)
  • `OPENAI_API_KEY` — Fallback API key (legacy compatibility)

Optional configuration:

  • `AI_PROVIDER` — Provider: `openai` or `ollama` (default: `openai`)
  • `AI_API_BASE` — API base URL (default: `https://api.openai.com/v1`)
  • `AI_MODEL` — Model name (default: `gpt-4o`)
  • `AI_PROMPT` — Custom system prompt for reflections

Quick Install

# Configure AI provider (OpenAI)
oc config set AI_PROVIDER openai
oc config set AI_API_KEY "sk-..."
oc config set AI_MODEL "gpt-4o"

# Or use Ollama (local, no API key needed)
oc config set AI_PROVIDER ollama
oc config set AI_API_BASE "http://localhost:11434/v1"
oc config set AI_MODEL "llama3"

Code Evidence

AI config defaults from `src/core/config.js:36-65`:

AI_PROVIDER: {
  description: 'AI provider: openai | ollama',
  default: 'openai'
},
AI_API_KEY: {
  description: 'API Key for AI chat (OpenAI compatible)',
  sensitive: true,
  envVar: 'AI_API_KEY',
  fallbackEnvVar: 'OPENAI_API_KEY'
},
AI_MODEL: {
  description: 'AI chat model name',
  default: 'gpt-4o'
},

Availability check (Ollama bypasses API key) from `src/ui/src/context/AIContext.jsx:77-80`:

const isAvailable = useMemo(() => {
  if (config.provider === 'ollama') return true;
  return config.hasApiKey;
}, [config.provider, config.hasApiKey]);

Default reflection prompt from `src/ui/src/context/AIContext.jsx:8`:

const DEFAULT_PROMPT = 'You are an AI within a journaling app. Your job is to help the user reflect on their thoughts in a thoughtful and kind manner...';

Common Errors

Error Message Cause Solution
`AI not available` No API key set and provider is OpenAI Run `oc config set AI_API_KEY "sk-..."`
`Failed to generate reflection` API error or network issue Check API key, base URL, and model name
Connection refused (Ollama) Ollama not running locally Start Ollama: `ollama serve`

Compatibility Notes

  • Ollama: When provider is `ollama`, no API key is required — `isAvailable` returns `true` automatically.
  • Language-aware: The reflection prompt includes the user's current language (Chinese or English) for localized responses.
  • Custom prompt: Users can override the default system prompt via `AI_PROMPT` config key.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment