It doesn’t appear that currently we can send regular documents via the api. There is imageUrls for an array of image files, but does not appear there is a comparable ‘documenturls’ to send documents like pdf. This would be a useful feature for programmatically adding document inputs.
You can’t get the direct file path of an uploaded PDF within a Pickaxe action. Instead, you must use the special PICKAXE_END_USER_RAW_DOC_URLS environment variable to get a temporary URL for the file and then download its contents to send to your API.
Why Direct Path Access Isn’t Possible
The environment where your Pickaxe action code runs is secure and isolated. For security reasons, it doesn’t have direct access to the file system where the PDF is temporarily stored after you upload it.
Connected actions receive the file information as a URL, not a local file path. Your code’s job is to take that URL, fetch the file from it, and then proceed with your API call.
How to Fix Your Code
You need to modify your Python script to first download the file using the provided URL. The requests library you’re already using is perfect for this.
Here is the corrected workflow and code:
Get the URL: Read the PICKAXE_END_USER_RAW_DOC_URLS environment variable. This will give you a list of URLs; for a single uploaded file, you’ll use the first one.
Download the File Content: Make an HTTP GET request to that URL to get the raw content of the PDF.
Send to API: In your existing API call, instead of trying to open a file from a path, you will send the downloaded file content directly.
Try this updated Python code:
import json
import requests
import os # Import the os library to access environment variables
# 1. Get the uploaded document's URL from the environment variable
# PICKAXE_END_USER_RAW_DOC_URLS provides a list of URLs for all uploaded files.
# We'll take the first one for this example.
doc_urls_str = os.environ.get("PICKAXE_END_USER_RAW_DOC_URLS")
if not doc_urls_str:
raise ValueError("No document was uploaded or the URL variable is not available.")
# The variable is a string representation of a list, so we parse it
# Example: '["https://url.to/your/file.pdf"]'
uploaded_file_urls = json.loads(doc_urls_str)
pdf_url = uploaded_file_urls[0]
# 2. Download the content of the PDF from the URL
try:
response = requests.get(pdf_url)
response.raise_for_status() # This will raise an error for bad responses (4xx or 5xx)
pdf_content = response.content
except requests.exceptions.RequestException as e:
raise SystemExit(f"Failed to download the file from URL: {e}")
# 3. Send the downloaded content to the document analysis API
VA_API_KEY = "YOUR_VA_API_KEY" # Replace with your API key
headers = {"Authorization": f"Basic {VA_API_KEY}"}
url = "https://api.va.landing.ai/v1/tools/agentic-document-analysis"
# The API expects the file content to be sent in a specific way.
# Typically, this is done using a 'files' multipart/form-data payload.
files = {
'file': ('filename.pdf', pdf_content, 'application/pdf')
}
api_response = requests.post(url, headers=headers, files=files)
# Process the api_response as needed
print(api_response.json())```
Let me know how it goes. Thx
That part about the lead developer was my LLM referencing a conversation with the lead developer of PA. Don’t mind that. The important part is how Pickaxe actions handle document URLs.
““You need to modify your Python script.” - I did not provide any script here.”
The section about the Python script is how you would set up your Pickaxe custom action’ code to handle sending documents, as it’s currently the only way to make it send documents. Does that make sense?
“Note also, I am talking about sending documents via API (same action as uploading documents via normal interface) not using an ‘Action’.”
Did you mean to say you want to upload a document to a Pickaxe from an external source via the API for processing?
Adding screenshots/loom would help us better understand what you’re trying to do.
No, I am not talking about sending to the studio API. I am talking about sending to a specific tool (a deployment). I want to simulate, via API, “upload a document to a Pickaxe for processing” as you note.
For example, you can send images to a pickaxe for processing via api using the ImageUrls parameter. I am asking for a similar parameter (call it documentUrls) to send documents to a pickaxe for processing.
@user14 At the moment, there isn’t a direct documentUrls parameter for the API, like there is for images. However, here’s a solid two-step process that lets you do exactly what you’re looking for:
@user14 My bad. I pushedd an update for my LLM today and its clearly messing up the resources another update is in order
Quick correction on my earlier note. As of today, the run API doesn’t accept general documents (there’s no documentUrls param; images via imageUrls are supported). What does work is:
Use the Studio API to create a document >> get documentId.
Attach that doc to your tool via Studio API.
Call the tool via the API embed.
Optionally detach/delete the doc after to keep it ephemeral.
This is the supported path until a native “attach doc at invocation” field is added to the run API.
Thanks for your help though, I did understand that I could upload something to knowledgebase and then use that, but my request is to make this easier by adding the documentUrls parameter to the api. Not sure how much harder that actually is than the already available imageurls, but seems it would be very similar in nature.