Skip to content

HTTPFS - OpenAI API Request Fails (HTTP 0 Internal Server Error) #21583

Description

@brianwyka

What happens?

I am using the httpfs extension to make an API call to OpenAI endpoint, replicating the same request with curl yields success, but in DuckDB it fails with an internal server error (unexpectedly). I am using the http secret to authenticate.

To Reproduce

Create secret:

CREATE SECRET openai (
  TYPE http, 
  SCOPE 'https://api.openai.com', 
  EXTRA_HTTP_HEADERS MAP {'Authorization': 'Bearer xxx'}
);

Confirm usage of secret:

FROM which_secret('https://api.openai.com', 'http');

Result:

┌─────────┬────────────┬─────────┐
│  name   │ persistent │ storage │
│ varchar │  varchar   │ varchar │
├─────────┼────────────┼─────────┤
│ openai  │ TEMPORARY  │ memory  │
└─────────┴────────────┴─────────┘

Call API:

SELECT * FROM read_json_auto('https://api.openai.com/v1/organization/costs?start_time=1772755200&group_by=line_item');

Error:

HTTP Error:
HTTP GET error on 'https://api.openai.com/v1/organization/costs?start_time=1772755200&group_by=line_item' (HTTP 0 Internal Server Error)

LINE 1: SELECT * FROM read_json_auto('https://api.openai.com/v1/organization/costs...

I've confirmed in the logs that the authentication is being included.

CALL enable_logging('HTTP');
SELECT * FROM duckdb_logs;

The logs indicate that the response is NULL:

{'request': {'type': GET, 'url': 'https://api.openai.com/v1/organization/costs?start_time=1772755200&group_by=line_item', 'headers': {User-Agent='duckdb/v1.5.0(osx_arm64) cli 3a3967aa81', Authorization=Bearer ***, Range='bytes=0-1', Content-Type=application/json}, 'start_time': '2026-03-24 13:23:24.082537', 'duration_ms': 2393}, 'response': NULL}

The following curl request succeeds:

curl -X GET -H "Authorization: Bearer ***" -H 'User-Agent: duckdb/v1.5.0(osx_arm64) cli 3a3967aa81' https://api.openai.com/v1/organization/costs\?start_time\=1772755200\&group_by\=line_item

OS:

MacOS - 24.6.0 Darwin Kernel Version 24.6.0: arm64

DuckDB Version:

1.5.0

DuckDB Client:

CLI

Hardware:

N/A

Full Name:

Brian Wyka

Affiliation:

LogicMonitor

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant data sets for reproducing the issue?

Yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions