dce-ai
v1.1.2
Published
Harvard DCE's wrapper for AI functionality
Readme
dce-ai
Harvard DCE's wrapper for AI functionality
Usage
// TODO: describe general usage, environment variables, etc.
Choosing an API host
Requests can be sent either straight to OpenAI or through Harvard HUIT's OpenAI relay (AIS OpenAI Direct). The relay is OpenAI-API-compatible, so the same models, structured outputs, and agent tools all work either way – only the base URL and auth header differ. The relay is approved for Level 3 confidential data and bills through a HUIT customer account instead of a credit card.
Pick a host per request:
import { runResponseRequest, APIHost, Models } from 'dce-ai';
const response = await runResponseRequest({
prompt: 'Summarize this discussion post.',
task: 'summarize-post',
model: Models.GPT4_1Mini,
apiHost: APIHost.HarvardOpenAIRelay,
});apiKey is still respected and is interpreted as a key for whichever host is
selected. runAgentRequest takes the same apiHost option.
Environment variables
| Variable | Purpose |
| --- | --- |
| OPENAI_API_KEY | API key used when talking to OpenAI directly |
| HARVARD_OPENAI_RELAY_API_KEY | API key from the Harvard API Portal, used when talking to the relay |
| HARVARD_OPENAI_RELAY_BASE_URL | Optional. Overrides the relay base URL (defaults to https://go.apis.huit.harvard.edu/ais-openai-direct/v2) |
| DCE_AI_API_HOST | Optional. Set to OpenAI or HarvardOpenAIRelay to pin the default host for every request |
When apiHost isn't passed, the host is resolved in this order:
DCE_AI_API_HOST, if it names a valid host- The relay, if
HARVARD_OPENAI_RELAY_API_KEYis set - OpenAI
The relay wins when both keys are present, since it's the approved path for
Level 3 data and bills through HUIT. Setups that only define OPENAI_API_KEY
keep going straight to OpenAI, and moving an app onto the relay takes no code
changes – just add the relay key. To keep using OpenAI directly on a machine
that also has a relay key, set DCE_AI_API_HOST=OpenAI or pass
apiHost: APIHost.OpenAI per request.
Notes on the relay
- Get an API key by registering an app in the Harvard API Portal. A HUIT customer account number (B#####) is required first.
- Per-app spend limits can be requested in the app description field. Once a
limit is hit, the relay returns
429until the period resets. - The default base URL points at v2. v1 is only available through 9/30/26, and budget limits apply separately to v1 and v2.
