from pathlib import Path
url = "https://api.vikingdb.cn-beijing.volces.com/openviking"
api_key = "your-api-key"
agent_id = "your-agent-id"
file_path = Path("your-file-path")
resource_to = "your-resource-path"
"Content-Type": "application/json",
"Authorization": "Bearer " + api_key,
"X-OpenViking-Agent": agent_id,
def post_json(path: str, payload: dict, timeout: float):
response = requests.post(
response.raise_for_status()
with file_path.open("rb") as file:
f"{url}/api/v1/resources/temp_upload",
"Authorization": "Bearer " + api_key,
"X-OpenViking-Agent": agent_id,
files={"file": (file_path.name, file, "application/octet-stream")},
result.raise_for_status()
print(json.dumps(result, ensure_ascii=False, indent=2))
temp_file_id = result["result"]["temp_file_id"]
"temp_file_id": temp_file_id,
"source_name": file_path.name,
print(json.dumps(result, ensure_ascii=False, indent=2))