Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Use billing subdomain
Jakub Novakf7d51d8b2f79
diff --git a/apps/web/src/app/(dashboard)/dashboard/page.tsx b/apps/web/src/app/(dashboard)/dashboard/page.tsxindex 872b149c5..ac0ba0ffa 100644--- a/apps/web/src/app/(dashboard)/dashboard/page.tsx+++ b/apps/web/src/app/(dashboard)/dashboard/page.tsx@@ -91,10 +91,6 @@ const Dashboard = ({ user }) => {'apiUrl',process.env.NEXT_PUBLIC_API_URL || '')- const billingUrlState = useLocalStorage(- 'billingUrl',- process.env.NEXT_PUBLIC_BILLING_API_URL || ''- )const initialTab =tab && menuLabels.includes(tab as MenuLabel)@@ -167,7 +163,6 @@ const Dashboard = ({ user }) => {setTeams={setTeams}setCurrentTeam={setCurrentTeam}apiUrlState={apiUrlState}- billingUrlState={billingUrlState}/></div></>@@ -230,16 +225,18 @@ const MenuItem = ({onClick: () => void}) => (<div- className={`flex w-fit md:w-full hover:bg-[#995100] hover:cursor-pointer rounded-lg items-center p-2 space-x-2 ${selected ? 'bg-[#995100]' : ''- }`}+ className={`flex w-fit md:w-full hover:bg-[#995100] hover:cursor-pointer rounded-lg items-center p-2 space-x-2 ${+ selected ? 'bg-[#995100]' : ''+ }`}onClick={onClick}><Icon width={20} height={20} /><p- className={`${!label || !window.matchMedia('(min-width: 768)').matches+ className={`${+ !label || !window.matchMedia('(min-width: 768)').matches? 'sr-only sm:not-sr-only': ''- }`}+ }`}>{label[0].toUpperCase() + label.slice(1)}</p>@@ -254,7 +251,6 @@ function MainContent({setTeams,setCurrentTeam,apiUrlState,- billingUrlState,}: {selectedItem: MenuLabeluser: E2BUser@@ -263,18 +259,13 @@ function MainContent({setTeams: (teams: Team[]) => voidsetCurrentTeam: (team: Team) => voidapiUrlState: [string, (value: string) => void]- billingUrlState: [string, (value: string) => void]}) {switch (selectedItem) {case 'personal':- return <PersonalContent user={user} billingUrl={billingUrlState[0]} />+ return <PersonalContent user={user} apiUrl={apiUrlState[0]} />case 'keys':return (- <KeysContent- currentTeam={team}- user={user}- billingUrl={billingUrlState[0]}- />+ <KeysContent currentTeam={team} user={user} apiUrl={apiUrlState[0]} />)case 'sandboxes':return <SandboxesContent team={team} apiUrl={apiUrlState[0]} />@@ -287,9 +278,9 @@ function MainContent({/>)case 'usage':- return <UsageContent team={team} billingUrl={billingUrlState[0]} />+ return <UsageContent team={team} apiUrl={apiUrlState[0]} />case 'billing':- return <BillingContent team={team} billingUrl={billingUrlState[0]} />+ return <BillingContent team={team} apiUrl={apiUrlState[0]} />case 'team':return (<TeamContent@@ -298,15 +289,11 @@ function MainContent({teams={teams}setTeams={setTeams}setCurrentTeam={setCurrentTeam}- billingUrl={billingUrlState[0]}+ apiUrl={apiUrlState[0]}/>)case 'developer':- return (- <DeveloperContent- apiUrlState={apiUrlState}- />- )+ return <DeveloperContent domainState={apiUrlState} />default:return <ErrorContent />}diff --git a/apps/web/src/components/Dashboard/Billing.tsx b/apps/web/src/components/Dashboard/Billing.tsxindex 8c6a01d84..97e7c3828 100644--- a/apps/web/src/components/Dashboard/Billing.tsx+++ b/apps/web/src/components/Dashboard/Billing.tsx@@ -29,10 +29,10 @@ interface Invoice {export const BillingContent = ({team,- billingUrl,+ apiUrl,}: {team: Team- billingUrl: string+ apiUrl: string}) => {const [invoices, setInvoices] = useState<Invoice[]>([])const [credits, setCredits] = useState<number | null>(null)@@ -40,11 +40,14 @@ export const BillingContent = ({useEffect(() => {const getInvoices = async function getInvoices() {setInvoices([])- const res = await fetch(`${billingUrl}/teams/${team.id}/invoices`, {- headers: {- 'X-Team-API-Key': team.apiKeys[0],- },- })+ const res = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/invoices`,+ {+ headers: {+ 'X-Team-API-Key': team.apiKeys[0],+ },+ }+ )if (!res.ok) {// TODO: add sentry errorconsole.log(res)@@ -55,11 +58,14 @@ export const BillingContent = ({setInvoices(invoices)setCredits(null)- const creditsRes = await fetch(`${billingUrl}/teams/${team.id}/usage`, {- headers: {- 'X-Team-API-Key': team.apiKeys[0],- },- })+ const creditsRes = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/usage`,+ {+ headers: {+ 'X-Team-API-Key': team.apiKeys[0],+ },+ }+ )const credits = await creditsRes.json()setCredits(credits.credits)}@@ -108,7 +114,7 @@ export const BillingContent = ({<div className="flex flex-col items-start justify-center pb-10"><div className="flex items-center space-x-4"><h2>Pro tier</h2>- <SwitchToProButton billingApiURL={billingUrl} team={team} />+ <SwitchToProButton apiUrl={apiUrl} team={team} /></div><ul className="flex flex-col list-disc list-inside text-neutral-400"><li>One-time $100 credits</li>diff --git a/apps/web/src/components/Dashboard/Developer.tsx b/apps/web/src/components/Dashboard/Developer.tsxindex f2c3eda74..7896e8795 100644--- a/apps/web/src/components/Dashboard/Developer.tsx+++ b/apps/web/src/components/Dashboard/Developer.tsx@@ -1,15 +1,18 @@'use client'import { Button } from '../Button'+import { useState } from 'react'-const defaultAPIUrl = process.env.NEXT_PUBLIC_API_URL || ''+const DEFAULT_DOMAIN = 'e2b.dev'+const DOMAIN = process.env.NEXT_PUBLIC_DOMAIN || DEFAULT_DOMAINexport const DeveloperContent = ({- apiUrlState,+ domainState,}: {- apiUrlState: [string, (value: string) => void]+ domainState: [string, (value: string) => void]}) => {- const [apiUrl, setApiUrl] = apiUrlState+ const [domain, setDomain] = domainState+ const [url, setUrl] = useState<string>(domain)function isUrl(url: string) {try {@@ -20,12 +23,26 @@ export const DeveloperContent = ({}}- function removeApiSubdomain(url: URL): string {- const hostParts = url.host.split('.')- if (hostParts.length > 2 && hostParts[0] === 'api') {- return hostParts.slice(1).join('.')+ function changeUrl(url: string) {+ setUrl(url)++ // Add protocol if missing+ let urlWithProtocol: string = url+ if (!url.startsWith('http://') && !url.startsWith('https://')) {+ urlWithProtocol = `https://${url}`+ }++ if (isUrl(urlWithProtocol)) {+ const domain = new URL(urlWithProtocol).host+ let hostParts = domain.split('.')+ if (hostParts.length > 2 && hostParts[0] === 'api') {+ hostParts = hostParts.slice(1)+ }+ setDomain(hostParts.join('.'))+ } else {+ console.log('Invalid URL')+ setDomain('Invalid URL')}- return url.host}return (@@ -35,10 +52,12 @@ export const DeveloperContent = ({<span className="font-bold text-neutral-300 pb-2">API URL</span><span className="text-sm text-neutral-300 pb-4">- Set API URL so the dashboard can connect to your E2B Cluster and correctly display running sandboxes and templates.+ Set API URL so the dashboard can connect to your E2B Cluster and+ correctly display running sandboxes and templates.</span>- {apiUrl !== defaultAPIUrl && (+ {/* Env var has to be set if the domain is not equal to the default */}+ {domain !== DEFAULT_DOMAIN && (<divclassName="bg-white/5 border-l-4 border-orange-500/20 text-gray-300 p-4 mb-4 lg:w-1/2 w-full"role="alert"@@ -47,15 +66,12 @@ export const DeveloperContent = ({Setting custom API URL in the E2B SDK & CLI</h4><div className="text-sm text-gray-400">- In your environment variables, set the <code>E2B_DOMAIN</code> variable to your- custom domain:+ In your environment variables, set the <code>E2B_DOMAIN</code>{' '}+ variable to your custom domain:<br /><pre className="mt-2 w-full bg-neutral-700 px-2 py-1 rounded-md text-brand-300">- E2B_DOMAIN={- isUrl(apiUrl)- ? `"${removeApiSubdomain(new URL(apiUrl))}"`- : 'Invalid URL'- }+ E2B_DOMAIN=+ {domain ?? 'Invalid URL'}</pre></div></div>@@ -65,13 +81,10 @@ export const DeveloperContent = ({<inputtype="text"className="w-1/2 border border-white/10 text-sm focus:outline-none outline-none rounded-md p-2"- value={apiUrl}- onChange={(e) => setApiUrl(e.target.value)}+ value={url}+ onChange={(e) => changeUrl(e.target.value)}/>- <Button- variant="desctructive"- onClick={() => setApiUrl(defaultAPIUrl)}- >+ <Button variant="desctructive" onClick={() => changeUrl(DOMAIN)}>Reset to default</Button></div>diff --git a/apps/web/src/components/Dashboard/Keys.tsx b/apps/web/src/components/Dashboard/Keys.tsxindex 8790d7cc7..e17b36549 100644--- a/apps/web/src/components/Dashboard/Keys.tsx+++ b/apps/web/src/components/Dashboard/Keys.tsx@@ -46,11 +46,11 @@ type TeamApiKey = {export const KeysContent = ({currentTeam,user,- billingUrl,+ apiUrl,}: {currentTeam: Teamuser: E2BUser- billingUrl: string+ apiUrl: string}) => {const { toast } = useToast()const [isKeyDialogOpen, setIsKeyDialogOpen] = useState(false)@@ -60,10 +60,11 @@ export const KeysContent = ({const [newApiKeyInput, setNewApiKeyInput] = useState<string>('')const [apiKeys, setApiKeys] = useState<TeamApiKey[]>([])+ console.log(apiUrl)useEffect(() => {async function fetchApiKeys() {const res = await fetch(- `${billingUrl}/teams/${currentTeam.id}/api-keys`,+ `https://billing.${apiUrl}/teams/${currentTeam.id}/api-keys`,{headers: {'X-USER-ACCESS-TOKEN': user.accessToken,@@ -85,7 +86,7 @@ export const KeysContent = ({}fetchApiKeys()- }, [currentTeam])+ }, [apiUrl, currentTeam])async function deleteApiKey() {if (apiKeys.length === 1) {@@ -97,7 +98,7 @@ export const KeysContent = ({}const res = await fetch(- `${billingUrl}/teams/${currentTeam.id}/api-keys/${currentKey?.id}`,+ `https://billing.${apiUrl}/teams/${currentTeam.id}/api-keys/${currentKey?.id}`,{method: 'DELETE',headers: {@@ -119,16 +120,19 @@ export const KeysContent = ({}async function createApiKey() {- const res = await fetch(`${billingUrl}/teams/${currentTeam.id}/api-keys`, {- method: 'POST',- headers: {- 'X-USER-ACCESS-TOKEN': user.accessToken,- 'Content-Type': 'application/json',- },- body: JSON.stringify({- name: newApiKeyInput,- }),- })+ const res = await fetch(+ `https://billing.${apiUrl}/teams/${currentTeam.id}/api-keys`,+ {+ method: 'POST',+ headers: {+ 'X-USER-ACCESS-TOKEN': user.accessToken,+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify({+ name: newApiKeyInput,+ }),+ }+ )if (!res.ok) {toast({@@ -149,7 +153,7 @@ export const KeysContent = ({async function updateApiKey() {const res = await fetch(- `${billingUrl}/teams/${currentTeam.id}/api-keys/${currentKey?.id}`,+ `https://billing.${apiUrl}/teams/${currentTeam.id}/api-keys/${currentKey?.id}`,{method: 'PATCH',headers: {diff --git a/apps/web/src/components/Dashboard/Personal.tsx b/apps/web/src/components/Dashboard/Personal.tsxindex 419163685..10937ae31 100644--- a/apps/web/src/components/Dashboard/Personal.tsx+++ b/apps/web/src/components/Dashboard/Personal.tsx@@ -9,10 +9,10 @@ import { E2BUser } from '@/utils/useUser'export const PersonalContent = ({user,- billingUrl,+ apiUrl,}: {user: E2BUser- billingUrl: string+ apiUrl: string}) => {const { toast } = useToast()const [hovered, setHovered] = useState<boolean>(false)@@ -33,7 +33,7 @@ export const PersonalContent = ({}const updateUserEmail = async () => {- const res = await fetch(`${billingUrl}/users`, {+ const res = await fetch(`https://billing.${apiUrl}/users`, {method: 'PATCH',headers: {'Content-Type': 'application/json',diff --git a/apps/web/src/components/Dashboard/Team.tsx b/apps/web/src/components/Dashboard/Team.tsxindex ff580dbed..574d55085 100644--- a/apps/web/src/components/Dashboard/Team.tsx+++ b/apps/web/src/components/Dashboard/Team.tsx@@ -45,14 +45,14 @@ export const TeamContent = ({teams,setTeams,setCurrentTeam,- billingUrl,+ apiUrl,}: {team: Teamuser: E2BUserteams: Team[]setTeams: (teams: Team[]) => voidsetCurrentTeam: (team: Team) => void- billingUrl: string+ apiUrl: string}) => {const [isDialogOpen, setIsDialogOpen] = useState(false)const [currentMemberId, setCurrentMemberId] = useState<string | null>(null)@@ -64,12 +64,15 @@ export const TeamContent = ({useEffect(() => {const getTeamMembers = async () => {- const res = await fetch(`${billingUrl}/teams/${team.id}/users`, {- headers: {- 'X-User-Access-Token': user.accessToken,- 'X-Team-API-Key': team.apiKeys[0],- },- })+ const res = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/users`,+ {+ headers: {+ 'X-User-Access-Token': user.accessToken,+ 'X-Team-API-Key': team.apiKeys[0],+ },+ }+ )if (!res.ok) {toast({@@ -101,14 +104,17 @@ export const TeamContent = ({}const deleteUserFromTeam = async () => {- const res = await fetch(`${billingUrl}/teams/${team.id}/users`, {- method: 'DELETE',- headers: {- 'X-User-Access-Token': user.accessToken,- 'Content-Type': 'application/json',- },- body: JSON.stringify({ user_id: currentMemberId }),- })+ const res = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/users`,+ {+ method: 'DELETE',+ headers: {+ 'X-User-Access-Token': user.accessToken,+ 'Content-Type': 'application/json',+ },+ body: JSON.stringify({ user_id: currentMemberId }),+ }+ )if (!res.ok) {toast({@@ -124,7 +130,7 @@ export const TeamContent = ({}const changeTeamName = async () => {- const res = await fetch(`${billingUrl}/teams/${team.id}`, {+ const res = await fetch(`https://billing.${apiUrl}/teams/${team.id}`, {headers: {'X-Team-API-Key': team.apiKeys[0],'Content-Type': 'application/json',@@ -161,14 +167,17 @@ export const TeamContent = ({return}- const res = await fetch(`${billingUrl}/teams/${team.id}/users`, {- headers: {- 'X-User-Access-Token': user.accessToken,- 'Content-Type': 'application/json',- },- method: 'POST',- body: JSON.stringify({ user_email: userToAdd.trim() }),- })+ const res = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/users`,+ {+ headers: {+ 'X-User-Access-Token': user.accessToken,+ 'Content-Type': 'application/json',+ },+ method: 'POST',+ body: JSON.stringify({ user_email: userToAdd.trim() }),+ }+ )if (!res.ok) {toast({diff --git a/apps/web/src/components/Dashboard/Usage.tsx b/apps/web/src/components/Dashboard/Usage.tsxindex f195fe8a0..74106513e 100644--- a/apps/web/src/components/Dashboard/Usage.tsx+++ b/apps/web/src/components/Dashboard/Usage.tsx@@ -23,10 +23,10 @@ type Series = {export const UsageContent = ({team,- billingUrl,+ apiUrl,}: {team: Team- billingUrl: string+ apiUrl: string}) => {const [vcpuData, setVcpuData] = useState<Series[]>([])const [vcpuHoursThisMonth, setVcpuHoursThisMonth] = useState<@@ -45,11 +45,14 @@ export const UsageContent = ({setRamData([])setCostUsage([])- const response = await fetch(`${billingUrl}/teams/${team.id}/usage`, {- headers: {- 'X-Team-API-Key': team.apiKeys[0],- },- })+ const response = await fetch(+ `https://billing.${apiUrl}/teams/${team.id}/usage`,+ {+ headers: {+ 'X-Team-API-Key': team.apiKeys[0],+ },+ }+ )if (!response.ok) {// TODO: Add sentry event heretoast({diff --git a/apps/web/src/components/Pricing/SwitchToProButton.tsx b/apps/web/src/components/Pricing/SwitchToProButton.tsxindex b0d0aee03..98558a8cf 100644--- a/apps/web/src/components/Pricing/SwitchToProButton.tsx+++ b/apps/web/src/components/Pricing/SwitchToProButton.tsx@@ -9,8 +9,8 @@ import Spinner from '@/components/Spinner'import { TierActiveTag } from './TierActiveTag'-function createCheckout(billingApiURL: string, tierID: string, teamID: string) {- return fetch(`${billingApiURL}/checkouts`, {+function createCheckout(apiUrl: string, tierID: string, teamID: string) {+ return fetch(`https://billing.${apiUrl}/checkouts`, {method: 'POST',headers: {'Content-Type': 'application/json',@@ -22,13 +22,7 @@ function createCheckout(billingApiURL: string, tierID: string, teamID: string) {})}-function SwitchTierButton({- team,- billingApiURL,-}: {- team: Team- billingApiURL: string-}) {+function SwitchTierButton({ team, apiUrl }: { team: Team; apiUrl: string }) {const { user, isLoading } = useUser()const [error, setError] = useState('')@@ -40,7 +34,7 @@ function SwitchTierButton({}const response = await createCheckout(- billingApiURL,+ apiUrl,tiers.pro.id,user.teams[0].id)@@ -67,10 +61,7 @@ function SwitchTierButton({// Only show the button if the user is on the base_v1 tier.// Teams can have custom tiers. We only want the button to users on the free tier.- if (- !billingApiURL ||- (team.tier !== tiers.hobby.id && team.tier !== tiers.pro.id)- ) {+ if (!apiUrl || (team.tier !== tiers.hobby.id && team.tier !== tiers.pro.id)) {return}