[Question]: Issues with Implementing Search Function via FastAPI Based on Documentation
Describe your problem
Hello, Developer,
I am developing some AI applications using Python FastAPI and trying to call the API interfaces as described in the documentation. However, I noticed that the documentation only allows API Token-based authentication, but I found that the HTTP API provided in the documentation does not implement the functionality I need, specifically the search feature.
For example, the frontend calls the following URL: http://localhost/v1/chunk/retrieval_test, but I am unable to achieve the same functionality via the HTTP API.
Could you please guide me on how to implement these features, or point me to the function or method in the source code that handles the same Authorization and Session management as the original Web CLI? Or is there any other reference documentation that could help me solve this issue?
Thank you for your assistance!
I use port 3001 with reverse proxy (Nginx)
I made a few edits in nginx.conf and default files. When checking the API URLs in the error with Curl, the errors persist even though '200 OK'.
Like:
root@IP:~# curl -I https://x.me/api/system/update-env HTTP/1.1 200 OK Server: nginx/1.18.0 (Ubuntu) Date: Sat, 15 Feb 2025 09:35:03 GMT Content-Type: text/html; charset=utf-8 Content-Length: 1690 Connection: keep-alive X-Powered-By: Express Vary: Origin ETag: W/"69a-tVI3FpcWE0szMcTWI5ao83oYY9Y"
You have set up NGINX likely incorrectly as a reverse proxy. You are getting back the generic 502 error page from NGINX - that is why it is an HTML response, you are never reaching the actual app endpoint
server {
# Enable websocket connections for agent protocol.
location ~* ^/api/agent-invocation/(.*) {
proxy_pass http://0.0.0.0:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
listen 80;
server_name [insert FQDN here];
location / {
# Prevent timeouts on long-running requests.
proxy_connect_timeout 605;
proxy_send_timeout 605;
proxy_read_timeout 605;
send_timeout 605;
keepalive_timeout 605;
# Enable readable HTTP Streaming for LLM streamed responses
proxy_buffering off;
proxy_cache off;
# Proxy your locally running service
proxy_pass http://0.0.0.0:3001;
}
}
You have set up NGINX likely incorrectly as a reverse proxy. You are getting back the generic 502 error page from NGINX - that is why it is an HTML response, you are never reaching the actual app endpoint
server { # Enable websocket connections for agent protocol. location ~* ^/api/agent-invocation/(.*) { proxy_pass http://0.0.0.0:3001; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } listen 80; server_name [insert FQDN here]; location / { # Prevent timeouts on long-running requests. proxy_connect_timeout 605; proxy_send_timeout 605; proxy_read_timeout 605; send_timeout 605; keepalive_timeout 605; # Enable readable HTTP Streaming for LLM streamed responses proxy_buffering off; proxy_cache off; # Proxy your locally running service proxy_pass http://0.0.0.0:3001; } }
When an error occurs on the API entry screen, the container closes and the following log is given:
[collector] info: [TikTokenTokenizer] Initialized new TikTokenTokenizer instance. [collector] info: Collector hot directory and tmp storage wiped! [collector] info: Document processor app listening on port 8888 Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 778ms
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient()
or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
import { PrismaClient } from '@prisma/client/edge' const prisma = new PrismaClient()
See other ways of importing Prisma Client: http://pris.ly/d/importing-client
Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Datasource "db": SQLite database "anythingllm.db" at "file:../storage/anythingllm.db"
27 migrations found in prisma/migrations
No pending migrations to apply. ┌─────────────────────────────────────────────────────────┐ │ Update available 5.3.1 -> 6.3.1 │ │ │ │ This is a major update - please follow the guide at │ │ https://pris.ly/d/major-version-upgrade │ │ │ │ Run the following to update │ │ npm i --save-dev prisma@latest │ │ npm i @prisma/client@latest │ └─────────────────────────────────────────────────────────┘ [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: [TokenManager] Initialized new TokenManager instance for model: gpt-3.5-turbo [backend] info: [TokenManager] Returning existing instance for model: gpt-3.5-turbo [backend] info: [TELEMETRY ENABLED] Anonymous Telemetry enabled. Telemetry helps Mintplex Labs Inc improve AnythingLLM. [backend] info: prisma:info Starting a sqlite pool with 5 connections. [backend] info: [TELEMETRY SENT] {"event":"server_boot","distinctId":"56bdd1d4-f8ee-473e-847b-9dc2b8270ebc","properties":{"commit":"--","runtime":"docker"}} [backend] info: [CommunicationKey] RSA key pair generated for signed payloads within AnythingLLM services. [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: Primary server in HTTP mode listening on port 3001 [backend] info: [BackgroundWorkerService] Feature is not enabled and will not be started. [backend] info: [MetaGenerator] fetching custom meta tag settings... [collector] info: [TikTokenTokenizer] Initialized new TikTokenTokenizer instance. [collector] info: Collector hot directory and tmp storage wiped! [collector] info: Document processor app listening on port 8888 Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 715ms
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient()
or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
import { PrismaClient } from '@prisma/client/edge' const prisma = new PrismaClient()
See other ways of importing Prisma Client: http://pris.ly/d/importing-client
Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Datasource "db": SQLite database "anythingllm.db" at "file:../storage/anythingllm.db"
27 migrations found in prisma/migrations
No pending migrations to apply. [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: [TokenManager] Initialized new TokenManager instance for model: gpt-3.5-turbo [backend] info: [TokenManager] Returning existing instance for model: gpt-3.5-turbo [backend] info: [TELEMETRY ENABLED] Anonymous Telemetry enabled. Telemetry helps Mintplex Labs Inc improve AnythingLLM. [backend] info: prisma:info Starting a sqlite pool with 5 connections. [backend] info: [TELEMETRY SENT] {"event":"server_boot","distinctId":"56bdd1d4-f8ee-473e-847b-9dc2b8270ebc","properties":{"commit":"--","runtime":"docker"}} [backend] info: [CommunicationKey] RSA key pair generated for signed payloads within AnythingLLM services. [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: Primary server in HTTP mode listening on port 3001 [backend] info: [BackgroundWorkerService] Feature is not enabled and will not be started. [collector] info: [TikTokenTokenizer] Initialized new TikTokenTokenizer instance. [collector] info: Collector hot directory and tmp storage wiped! [collector] info: Document processor app listening on port 8888 Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v5.3.1) to ./node_modules/@prisma/client in 700ms
Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
import { PrismaClient } from '@prisma/client' const prisma = new PrismaClient()
or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
import { PrismaClient } from '@prisma/client/edge' const prisma = new PrismaClient()
See other ways of importing Prisma Client: http://pris.ly/d/importing-client
Environment variables loaded from .env Prisma schema loaded from prisma/schema.prisma Datasource "db": SQLite database "anythingllm.db" at "file:../storage/anythingllm.db"
27 migrations found in prisma/migrations
No pending migrations to apply. [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: [TokenManager] Initialized new TokenManager instance for model: gpt-3.5-turbo [backend] info: [TokenManager] Returning existing instance for model: gpt-3.5-turbo [backend] info: [TELEMETRY ENABLED] Anonymous Telemetry enabled. Telemetry helps Mintplex Labs Inc improve AnythingLLM. [backend] info: prisma:info Starting a sqlite pool with 5 connections. [backend] info: [TELEMETRY SENT] {"event":"server_boot","distinctId":"56bdd1d4-f8ee-473e-847b-9dc2b8270ebc","properties":{"commit":"--","runtime":"docker"}} [backend] info: [CommunicationKey] RSA key pair generated for signed payloads within AnythingLLM services. [backend] info: [EncryptionManager] Loaded existing key & salt for encrypting arbitrary data. [backend] info: Primary server in HTTP mode listening on port 3001 [backend] info: [BackgroundWorkerService] Feature is not enabled and will not be started. [backend] info: [MetaGenerator] fetching custom meta tag settings... [backend] error: Error: The OPENAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the OpenAI client with an apiKey option, like new OpenAI({ apiKey: 'My API Key' }). at new OpenAI (/app/server/node_modules/openai/index.js:53:19) at openAiModels (/app/server/utils/helpers/customModels.js:84:18) at getCustomModels (/app/server/utils/helpers/customModels.js:40:20) at /app/server/endpoints/system.js:953:41 at Layer.handle [as handle_request] (/app/server/node_modules/express/lib/router/layer.js:95:5) at next (/app/server/node_modules/express/lib/router/route.js:149:13) at /app/server/utils/middleware/multiUserProtected.js:60:7 at Layer.handle [as handle_request] (/app/server/node_modules/express/lib/router/layer.js:95:5) at next (/app/server/node_modules/express/lib/router/route.js:149:13) at validatedRequest (/app/server/utils/middleware/validatedRequest.js:20:5) [backend] info: [GeminiLLM] Using cached models API response. [backend] info: EmbeddingEngine changed from undefined to native - resetting undefined namespaces [backend] info: [Event Logged] - workspace_vectors_reset [backend] info: Resetting anythingllm managed vector namespaces for /usr/local/bin/docker-entrypoint.sh: line 7: 111 Illegal instruction (core dumped) node /app/server/index.js
Also, where should I enter the code you provided? I entered it into the default. There is no .conf file for domain, and I haven't edited the nginx.conf. /etc/nginx/sites-enabled/default content:
https://docs.google.com/document/d/1yZM_jrl5e_eDGCuqNk1ZCF9zSE_BTKExGaOnWO0ubyc/edit?usp=sharing
You are 301'ing port 80 in the second block which will go to the first blocks port 80 definition.
root /var/www/html; -> probably does not exist
You should have a single server block and that should be returning $host$request_uri, not a 301 to /var/www/html which likely does not exist.
What i posted above is the only server block your need. Also dont forget to reload the service when you change NGINX