microsoft/autogen · error · Error

Failed to fetch gallery

Error message

Failed to fetch gallery

What it means

Catch-all raised when the plain-OpenAI embeddings.create call raises; the original exception is preserved as __cause__. Common underlying errors: 401 invalid API key, 429 quota/rate-limit, model name not available to the key's organization, or network issues.

Source

Thrown at python/packages/autogen-studio/frontend/src/components/views/gallery/api.ts:27

        headers: this.getHeaders(),
      }
    );
    const data = await response.json();
    if (!data.status)
      throw new Error(data.message || "Failed to fetch galleries");
    return data.data;
  }

  async getGallery(galleryId: number, userId: string): Promise<Gallery> {
    const response = await fetch(
      `${this.getBaseUrl()}/gallery/${galleryId}?user_id=${userId}`,
      {
        headers: this.getHeaders(),
      }
    );
    const data = await response.json();
    if (!data.status)
      throw new Error(data.message || "Failed to fetch gallery");
    return data.data;
  }

  async createGallery(
    galleryData: Partial<Gallery>,
    userId: string
  ): Promise<Gallery> {
    const gallery = {
      ...galleryData,
      user_id: userId,
    };

    console.log("Creating gallery with data:", gallery);

    const response = await fetch(`${this.getBaseUrl()}/gallery/`, {
      method: "POST",
      headers: this.getHeaders(),
      body: JSON.stringify(gallery),

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Read e.__cause__ for the true OpenAI error before changing anything.
  2. Ensure `openai_api_key` is set (env var OPENAI_API_KEY or explicit field) and is current.
  3. Use a valid model id for api.openai.com, e.g. "text-embedding-3-small" or "text-embedding-3-large".
  4. Handle 429s with exponential-backoff retry around the tool call.

Example fix

# before
config = AzureAISearchConfig(
    ..., embedding_provider="openai", embedding_model="text-embedding-3-small",
)  # openai_api_key missing -> 401 wrapped in ValueError

# after
config = AzureAISearchConfig(
    ..., embedding_provider="openai", embedding_model="text-embedding-3-small",
    openai_api_key=os.environ["OPENAI_API_KEY"],
)
Defensive patterns

Strategy: try-catch

Validate before calling

def openai_embedding_config_ok(cfg) -> bool:
    return bool(
        str(cfg.embedding_provider or "").lower() == "openai"
        and getattr(cfg, "openai_api_key", None)
        and cfg.embedding_model
    )

Try / catch

try:
    results = await tool.run(query)
except ValueError as e:
    if "embeddings with OpenAI" in str(e) and getattr(e.__cause__, "status_code", None) == 401:
        raise RuntimeError("OpenAI API key missing or invalid") from e
    raise

Prevention

When it happens

Trigger: Vector search with embedding_provider='openai' where openai_client.embeddings.create(model=embedding_model, input=query) throws — e.g. openai_api_key not set (so AsyncOpenAI got None), key invalid, model id typo like 'text-embedding-3-sm', or exhausted quota.

Common situations: Forgetting openai_api_key in the config when using the plain OpenAI provider; rotated/revoked keys; using Azure-style deployment names against api.openai.com; free-tier quota exhausted mid-run.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/1210a0313b803d23. Report an issue: GitHub.