Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ef99ad6
Rate limits and budgets
narengogi Sep 22, 2025
6d123db
remvoe bindings
narengogi Sep 30, 2025
d55ecf8
remove kv
narengogi Sep 30, 2025
169e7d2
Merge remote-tracking branch 'upstream/main' into feature/ratelimits-…
narengogi Sep 30, 2025
8407df1
rebase
narengogi Sep 30, 2025
1d99b8a
Apply suggestion from @matter-code-review[bot]
narengogi Oct 1, 2025
1c3d5c5
Apply suggestion from @matter-code-review[bot]
narengogi Oct 1, 2025
2b379fb
Apply suggestion from @matter-code-review[bot]
narengogi Oct 1, 2025
0bb75dd
Apply suggestion from @matter-code-review[bot]
narengogi Oct 1, 2025
05e42a3
handle settings
narengogi Oct 1, 2025
00c00e8
handle redis rate limiter tokens rate limiting when tokens to decreme…
narengogi Oct 7, 2025
a29315e
remove cache backend changes
narengogi Oct 9, 2025
9cc932d
remove unused imports
narengogi Oct 9, 2025
2505510
update settings example
narengogi Oct 9, 2025
bc56171
update settings initializer
narengogi Oct 9, 2025
99f6262
dont hardcode id
narengogi Oct 9, 2025
d331fd8
remove unused variable
narengogi Oct 9, 2025
f4cdbe3
handle nulls
narengogi Oct 9, 2025
d2ca7ef
remove import
narengogi Oct 9, 2025
b372b2f
delete transfer encoding for node
narengogi Oct 9, 2025
8a0eb99
rate limits with resets
narengogi Oct 9, 2025
a3d77ca
formatting
narengogi Oct 9, 2025
0b802a3
dont crash on unhandled exceptions
narengogi Oct 9, 2025
cf965b9
dont crash on unhandled exceptions
narengogi Oct 9, 2025
10f253d
handle refreshing the conf file at runtime
narengogi Oct 10, 2025
e125a6e
simplify ui and handle rat elimit ejection
narengogi Oct 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions conf.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"integrations": [
{
"provider": "anthropic",
"slug": "dev_team_anthropic",
"credentials": {
"apiKey": "sk-ant-"
},
"rate_limits": [
{
"type": "requests",
"unit": "rph",
"value": 3
},
{
"type": "tokens",
"unit": "rph",
"value": 3000
}
],
"models": [
{
"slug": "claude-3-7-sonnet-20250219",
"status": "active",
"pricing_config": null
}
]
}
]
}
Empty file removed conf_sample.json
Empty file.
76 changes: 76 additions & 0 deletions initializeSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export const defaultOrganisationDetails = {
id: 'self-hosted-organisation',
name: 'Portkey self hosted',
settings: {
debug_log: 1,
is_virtual_key_limit_enabled: 1,
allowed_guardrails: ['BASIC', 'PARTNER', 'PRO'],
},
workspaceDetails: {},
defaults: {
metadata: null,
},
usageLimits: [],
rateLimits: [],
organisationDefaults: {
input_guardrails: null,
},
};

const transformIntegrations = (integrations: any) => {
return integrations.map((integration: any) => {
return {
id: integration.slug, //need to do consistent hashing for caching
ai_provider_name: integration.provider,
model_config: {
...integration.credentials,
},
...(integration.credentials?.apiKey && {
key: integration.credentials.apiKey,
}),
slug: integration.slug,
usage_limits: null,
status: 'active',
integration_id: integration.slug,
object: 'virtual-key',
integration_details: {
id: integration.slug,
slug: integration.slug,
usage_limits: integration.usage_limits,
rate_limits: integration.rate_limits,
models: integration.models,
allow_all_models: integration.allow_all_models,
},
};
});
};

export const getSettings = async () => {
try {
const isFetchSettingsFromFile =
process?.env?.FETCH_SETTINGS_FROM_FILE === 'true';
if (!isFetchSettingsFromFile) {
return undefined;
}
let settings: any = undefined;
const { readFile } = await import('fs/promises');
const settingsFile = await readFile('./conf.json', 'utf-8');
const settingsFileJson = JSON.parse(settingsFile);

if (settingsFileJson) {
settings = {};
settings.organisationDetails = defaultOrganisationDetails;
if (settingsFileJson.integrations) {
settings.integrations = transformIntegrations(
settingsFileJson.integrations
);
}
return settings;
}
} catch (error) {
console.log(
'WARNING: unable to load settings from your conf.json file',
error
);
}
};
92 changes: 89 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"async-retry": "^1.3.3",
"avsc": "^5.7.7",
"hono": "^4.6.10",
"ioredis": "^5.8.0",
"jose": "^6.0.11",
"patch-package": "^8.0.0",
"ws": "^8.18.0",
Expand Down
13 changes: 13 additions & 0 deletions src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,16 @@ export enum BatchEndpoints {
COMPLETIONS = '/v1/completions',
EMBEDDINGS = '/v1/embeddings',
}

export const AtomicOperations = {
GET: 'GET',
RESET: 'RESET',
INCREMENT: 'INCREMENT',
DECREMENT: 'DECREMENT',
};

export enum RateLimiterKeyTypes {
VIRTUAL_KEY = 'VIRTUAL_KEY',
API_KEY = 'API_KEY',
INTEGRATION_WORKSPACE = 'INTEGRATION_WORKSPACE',
}
Loading