Skip to main content

POST /upload

Upload Pricing2Yaml configuration files to make them available for analysis via the chat endpoint. Uploaded files are stored in the static directory and can be referenced in subsequent queries.

Endpoint

POST http://localhost:8086/upload

Request

This endpoint expects a multipart form data request with a file upload.
file
file
required
YAML file containing Pricing2Yaml configurationContent-Type: Must be application/yaml or application/x-yamlFile Extension: .yaml or .yml

Response

Status Code: 201 Created
filename
string
The name of the uploaded file
relative_path
string
The relative path where the file can be accessed (e.g., /static/overleaf-2023.yaml)

Examples

Upload with cURL

curl -X POST http://localhost:8086/upload \
  -F '[email protected];type=application/yaml'

Upload with Python

import requests

with open('pricing.yaml', 'rb') as f:
    files = {
        'file': ('pricing.yaml', f, 'application/yaml')
    }
    response = requests.post(
        'http://localhost:8086/upload',
        files=files
    )

data = response.json()
print(f"Uploaded: {data['filename']}")
print(f"Path: {data['relative_path']}")

Upload with JavaScript

const formData = new FormData();
const fileInput = document.querySelector('input[type="file"]');
formData.append('file', fileInput.files[0]);

const response = await fetch('http://localhost:8086/upload', {
  method: 'POST',
  body: formData
});

const data = await response.json();
console.log('Uploaded:', data.filename);
console.log('Path:', data.relative_path);

Response Example

{
  "filename": "overleaf-2023.yaml",
  "relative_path": "/static/overleaf-2023.yaml"
}

Error Responses

400 Bad Request - Invalid Content Type

{
  "detail": "Invalid Content-Type: application/json. Only application/yaml is supported"
}
This error occurs when the uploaded file does not have the correct MIME type.

400 Bad Request - Missing File

{
  "detail": "Field required"
}
This error occurs when no file is included in the request.

Sample Pricing2Yaml File

Here’s an example of a valid Pricing2Yaml file structure:
overleaf-2023.yaml
saasName: Overleaf - Individual
syntaxVersion: '2.1'
version: '2023-11-27'
createdAt: '2023-11-27'
currency: USD
variables: {}
features:
  fastCompileServers:
    description: >-
      Compiles for users on premium plans always run on a dedicated pool of the
      fastest available servers.
    valueType: BOOLEAN
    defaultValue: true
    type: DOMAIN
  realTimeTrackChanges:
    description: >-
      Switch on track changes to see who made every change, accept or reject
      others' changes, and write comments.
    valueType: BOOLEAN
    defaultValue: false
    type: DOMAIN
  gitIntegration:
    description: >-
      You can clone your Overleaf project to a local repository, treating your
      Overleaf project as a remote repository that changes can be pushed to and
      pulled from.
    valueType: BOOLEAN
    defaultValue: false
    type: INTEGRATION
usageLimits:
  collaborators:
    description: Number of collaborators per project
    valueType: NUMERIC
    defaultValue: 1
    type: NON_RENEWABLE
    unit: users
plans:
  Free:
    price: 0
    unit: month
    features:
      fastCompileServers: false
      realTimeTrackChanges: false
      gitIntegration: false
    usageLimits:
      collaborators: 1
  Professional:
    price: 21
    unit: month
    features:
      fastCompileServers: true
      realTimeTrackChanges: true
      gitIntegration: true
    usageLimits:
      collaborators: 10

Using Uploaded Files

After uploading a file, you can reference it in chat queries:

Option 1: Automatic Reference (Single Upload)

If only one file has been uploaded, H.A.R.V.E.Y. automatically uses it:
curl -X POST http://localhost:8086/chat \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What is the cheapest plan?"
  }'

Option 2: Explicit YAML Content

Pass the YAML content directly in the chat request:
import requests

# Read the YAML file
with open('pricing.yaml', 'r') as f:
    yaml_content = f.read()

# Send to chat endpoint
response = requests.post(
    'http://localhost:8086/chat',
    json={
        'question': 'Find the optimal plan for 5 users',
        'pricing_yaml': yaml_content
    }
)

print(response.json()['answer'])

Option 3: Static File Reference

Access the uploaded file directly via the static files endpoint:
curl http://localhost:8086/static/overleaf-2023.yaml

File Management

Uploaded files are:
  • Stored in the directory specified by HARVEY_STATIC_DIR environment variable
  • Tracked in an in-memory pricing context database
  • Associated with a unique identifier (filename without extension)
  • Accessible via the static files endpoint at /static/{filename}

Deleting Uploaded Files

To remove an uploaded file:
curl -X DELETE http://localhost:8086/pricing/overleaf-2023.yaml
Response: 204 No Content (success) or 404 Not Found

Best Practices

Validate Before Upload

Ensure your Pricing2Yaml file follows the correct schema. Use the /chat endpoint with a validation query after upload.

Descriptive Filenames

Use clear, descriptive filenames like github-2024.yaml or slack-enterprise.yaml for easy identification.

Version Control

Include version information in the YAML file’s version field to track changes over time.

Test Uploads

After uploading, test with a simple query like “Summarize this pricing” to confirm the file is accessible.

Limitations

  • Only YAML files are accepted (MIME type: application/yaml or application/x-yaml)
  • File size limits depend on your FastAPI configuration
  • Files are stored in memory and on disk; large numbers of uploads may impact performance
  • No authentication/authorization is required (consider adding in production)
  • Uploaded files persist until explicitly deleted or the service restarts

Chat Endpoint

Use uploaded files in pricing queries

Pricing2Yaml Spec

Learn about the Pricing2Yaml format

Implementation Reference

The upload functionality is implemented in:
  • harvey_api/src/harvey_api/app.py:155 (upload endpoint)
  • harvey_api/src/harvey_api/file_manager.py:8 (file storage)
  • harvey_api/src/harvey_api/pricing_context.py (context tracking)

Build docs developers (and LLMs) love