JanDeDobbeleer/oh-my-posh · error

no api key found

Error message

no api key found

What it means

The OpenWeatherMap segment requires the api_key option, resolved as a template. getResult rejects the request before any HTTP call when the template renders to an empty string, because OWM's API cannot authenticate without an appid.

Source

Thrown at src/segments/owm.go:66

	if err != nil {
		log.Error(err)
		return false
	}

	return true
}

func (d *Owm) Template() string {
	return " {{ .Weather }} ({{ .Temperature }}{{ .UnitIcon }}) "
}

func (d *Owm) getResult() (*owmDataResponse, error) {
	response := new(owmDataResponse)

	apikey := d.options.Template(APIKey, "", d)
	if apikey == "" {
		return nil, errors.New("no api key found")
	}

	location := d.options.Template(Location, "", d)
	if location == "" {
		return nil, errors.New("no location found")
	}

	location = url.QueryEscape(location)

	units := d.options.String(Units, "standard")
	httpTimeout := d.options.Int(options.HTTPTimeout, options.DefaultHTTPTimeout)

	d.URL = fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?q=%s&units=%s&appid=%s", location, units, apikey)

	body, err := d.env.HTTPRequest(d.URL, nil, httpTimeout)
	if err != nil {
		return new(owmDataResponse), err
	}

View on GitHub (pinned to 0976794618)

Solutions

  1. Set api_key to a valid OpenWeatherMap API key in the segment config.
  2. If using a template like {{ .Env.OWM_API_KEY }}, export that environment variable before launching the shell.
  3. Remove surrounding quotes/whitespace issues so the template does not render empty.
  4. Get a free key from openweathermap.org if you do not have one.

Example fix

// before
{
  "type": "owm"
}
// after
{
  "type": "owm",
  "api_key": "your-openweathermap-appid"
}
Defensive patterns

Strategy: validation

Validate before calling

const key = process.env.OWM_API_KEY ?? cfg.api_key ?? ""
if (!key) {
  throw new Error("owm segment requires a non-empty api_key")
}

Try / catch

err := d.setStatus()
if err != nil {
  if err.Error() == "no api key found" {
    log.Warn("owm: set api_key in segment config")
    return // hide segment
  }
  return err
}

Prevention

When it happens

Trigger: Configuring an owm segment without api_key, with api_key = "", or with a template/property that resolves to empty at runtime (e.g. referencing a missing env var like {{ .Env.OWM_KEY }} that is unset).

Common situations: Copy-pasting a theme that expects an env var you never set, redacting the key when sharing config and forgetting to restore it, or a template typo producing an empty string.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of JanDeDobbeleer/oh-my-posh@0976794618 (2026-08-31). Data as JSON: /api/errors/1f61f4942f5a3844. Report an issue: GitHub.