Docker Space fails to call Ollama Cloud API - 404 "model not found"

I’ve deployed a FastAPI backend to HuggingFace Spaces (Docker SDK, public Space) that needs to make outbound HTTPS POST requests to Ollama Cloud API for embeddings.

What Works:

  • Space builds and starts successfully
  • Health check endpoint returns 200 OK
  • Requests from frontend reach the backend
  • Same exact API call works from my local machine and other environments

What Fails:

This succeeds from my local machine:

curl -X POST https://api.ollama.cloud/v1/embeddings
-H “Authorization: Bearer [API_KEY]”
-H “Content-Type: application/json”
-d ‘{“model”: “nomic-embed-text”, “input”: [“test”]}’

Returns: 768-dimension embedding successfully

Same request from HF Space Docker container: 404 error

Space Configuration:

  • SDK: Docker
  • Port: 7860
  • Dockerfile: Python 3.10-slim, uvicorn running FastAPI
  • OLLAMA_API_KEY stored as repository secret

Question:
Is there a network restriction or firewall rule on HF Spaces that blocks/modifies requests to api.ollama.cloud? Or is there a known issue with certain external APIs? The same code works perfectly locally but fails only when deployed to HF Spaces.

Any guidance would be appreciated!

Space indidginus/herbal-remedies-guide

1 Like

I tried it from the Gradio space and got 200 back. Seem like it’s not blocked…?

url = "https://api.ollama.cloud/v1/embeddings"
model = "nomic-embed-text"
key = "dummy"
payload = {"model":model,"input":["test"]}
headers = {"Authorization": f"Bearer {key}"}
response = requests.post(url, json=payload, headers=headers, timeout=30, allow_redirects=False, verify=False)
/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'api.ollama.cloud'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
https://api.ollama.cloud/v1/embeddings is working. Status code: 200