Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(context-dev): add Context.dev to hosted key rotation pool#5576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { contextDevClassifyNaicsTool } from '@/tools/context_dev/classify_naics' | ||
| import { contextDevGetBrandTool } from '@/tools/context_dev/get_brand' | ||
| import { CONTEXT_DEV_CREDIT_USD } from '@/tools/context_dev/hosting' | ||
| import { contextDevScrapeMarkdownTool } from '@/tools/context_dev/scrape_markdown' | ||
| import { contextDevScreenshotTool } from '@/tools/context_dev/screenshot' | ||
| import type { ToolConfig } from '@/tools/types' | ||
| function cost(tool: ToolConfig<any, any>, params: any, output: Record<string, unknown>) { | ||
| const pricing = tool.hosting?.pricing | ||
| if (!pricing || pricing.type !== 'custom') throw new Error('Expected custom pricing') | ||
| const result = pricing.getCost(params, output) | ||
| return typeof result === 'number' ? { cost: result } : result | ||
| } | ||
| describe('Context.dev hosted key pricing', () => { | ||
| it('declares hosting with the shared env prefix and BYOK provider on every tool', () => { | ||
| for (const tool of [ | ||
| contextDevScrapeMarkdownTool, | ||
| contextDevScreenshotTool, | ||
| contextDevGetBrandTool, | ||
| contextDevClassifyNaicsTool, | ||
| ]) { | ||
| expect(tool.hosting?.envKeyPrefix).toBe('CONTEXT_DEV_API_KEY') | ||
| expect(tool.hosting?.byokProviderId).toBe('context_dev') | ||
| } | ||
| }) | ||
| it('charges the reported credits at the per-credit rate for a 1-credit scrape', () => { | ||
| expect(cost(contextDevScrapeMarkdownTool, {}, { creditsConsumed: 1 }).cost).toBeCloseTo( | ||
| CONTEXT_DEV_CREDIT_USD | ||
| ) | ||
| }) | ||
| it('charges the reported credits at the per-credit rate for a 5-credit screenshot', () => { | ||
| expect(cost(contextDevScreenshotTool, {}, { creditsConsumed: 5 }).cost).toBeCloseTo( | ||
| 5 * CONTEXT_DEV_CREDIT_USD | ||
| ) | ||
| }) | ||
| it('charges the reported credits at the per-credit rate for a 10-credit brand lookup', () => { | ||
| expect(cost(contextDevGetBrandTool, {}, { creditsConsumed: 10 }).cost).toBeCloseTo( | ||
| 10 * CONTEXT_DEV_CREDIT_USD | ||
| ) | ||
| }) | ||
| it('charges zero when the response has no credit accounting', () => { | ||
| expect(cost(contextDevClassifyNaicsTool, {}, { creditsConsumed: null }).cost).toBe(0) | ||
| expect(cost(contextDevClassifyNaicsTool, {}, {}).cost).toBe(0) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import type { ToolHostingConfig } from '@/tools/types' | ||
| /** | ||
| * Env var prefix for Context.dev hosted keys. Provide keys as | ||
| * `CONTEXT_DEV_API_KEY_COUNT` plus `CONTEXT_DEV_API_KEY_1..N`. | ||
| */ | ||
| export const CONTEXT_DEV_API_KEY_PREFIX = 'CONTEXT_DEV_API_KEY' | ||
| /** | ||
| * Dollar cost of a single Context.dev credit. | ||
| * | ||
| * Estimated from the $25/month Developer plan (10,000 credits = $0.0025/credit) | ||
| * — https://www.context.dev/pricing. Endpoints cost 1, 5, or 10 credits | ||
| * depending on operation; actual usage is read from each response's | ||
| * `key_metadata.credits_consumed` rather than hardcoded per endpoint. | ||
| */ | ||
| export const CONTEXT_DEV_CREDIT_USD = 0.0025 | ||
| /** | ||
| * Build a Context.dev `hosting` config. Every Context.dev response reports the | ||
| * exact credits consumed via `key_metadata.credits_consumed`, already surfaced | ||
| * on tool output as `creditsConsumed` by `extractCreditMetadata` — so cost is | ||
| * read directly from the response rather than estimated per endpoint. | ||
| */ | ||
| export function contextDevHosting<P>(): ToolHostingConfig<P> { | ||
| return { | ||
| envKeyPrefix: CONTEXT_DEV_API_KEY_PREFIX, | ||
| apiKeyParam: 'apiKey', | ||
| byokProviderId: 'context_dev', | ||
| pricing: { | ||
| type: 'custom', | ||
| getCost: (_params, output) => { | ||
| const credits = (output.creditsConsumed as number | null) ?? 0 | ||
| return { cost: credits * CONTEXT_DEV_CREDIT_USD, metadata: { credits } } | ||
| }, | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }, | ||
| rateLimit: { | ||
| mode: 'per_request', | ||
| requestsPerMinute: 60, | ||
| }, | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.