Skip to main content
GET
https://api.keywordsai.co
/
api
/
files
/
{file_id}
/
content
import requests

file_id = "file-xyz789"
url = f"https://api.keywordsai.co/api/files/{file_id}/content/"
headers = {
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.get(url, headers=headers)

# Save to file
with open("batch_output.jsonl", "wb") as f:
    f.write(response.content)

print("File downloaded successfully")
{
  "error": {
    "message": "No such file: file-xyz789",
    "type": "invalid_request_error"
  }
}
Download the raw contents of a file. This is particularly useful for downloading batch output files after a batch job completes.
Customer credentials required: This endpoint requires your own OpenAI API key configured in Keywords AI dashboard (Settings → Providers).

Path parameters

file_id
string
required
The unique identifier of the file whose content you want to download. Format: file-xxxxx
file-xyz789

Response

Returns the raw file content. For JSONL files, each line is a separate JSON object.
{"id": "batch_req_abc123", "custom_id": "request-1", "response": {"status_code": 200, "request_id": "req_xyz", "body": {"id": "chatcmpl-abc", "object": "chat.completion", "created": 1711471533, "model": "gpt-4", "usage": {"prompt_tokens": 10, "completion_tokens": 50, "total_tokens": 60}, "choices": [{"index": 0, "message": {"role": "assistant", "content": "Hello! How can I assist you today?"}}]}}, "error": null}
{"id": "batch_req_def456", "custom_id": "request-2", "response": {"status_code": 200, "request_id": "req_uvw", "body": {"id": "chatcmpl-def", "object": "chat.completion", "created": 1711471534, "model": "gpt-3.5-turbo", "usage": {"prompt_tokens": 8, "completion_tokens": 40, "total_tokens": 48}, "choices": [{"index": 0, "message": {"role": "assistant", "content": "I'm doing well, thank you!"}}]}}, "error": null}
{
  "error": {
    "message": "No such file: file-xyz789",
    "type": "invalid_request_error"
  }
}
import requests

file_id = "file-xyz789"
url = f"https://api.keywordsai.co/api/files/{file_id}/content/"
headers = {
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.get(url, headers=headers)

# Save to file
with open("batch_output.jsonl", "wb") as f:
    f.write(response.content)

print("File downloaded successfully")