Skip to content

Commit af3a023

Browse files
committed
feat: add support for together-ai api token
1 parent 9b1774c commit af3a023

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function ensure<T>(value: T | undefined, message: string): T {
3636
return value;
3737
}
3838

39+
function getBaseUrl(token: string) {
40+
if (token.startsWith("csb_")) {
41+
return "https://api.codesandbox.io";
42+
}
43+
44+
return "https://api.together.ai/csb/sdk";
45+
}
46+
3947
export class CodeSandbox {
4048
private baseUrl: string;
4149
private apiToken: string;
@@ -44,13 +52,15 @@ export class CodeSandbox {
4452
public readonly sandbox: SandboxClient;
4553

4654
constructor(apiToken?: string, private readonly opts: ClientOpts = {}) {
47-
this.baseUrl = opts.baseUrl ?? "https://api.codesandbox.io";
4855
this.apiToken =
4956
apiToken ||
5057
ensure(
51-
typeof process !== "undefined" ? process.env?.CSB_API_KEY : undefined,
52-
"CSB_API_KEY is not set"
58+
typeof process !== "undefined"
59+
? process.env?.CSB_API_KEY || process.env?.TOGETHER_API_KEY
60+
: undefined,
61+
"CSB_API_KEY or TOGETHER_API_KEY is not set"
5362
);
63+
this.baseUrl = opts.baseUrl ?? getBaseUrl(this.apiToken);
5464

5565
this.apiClient = createClient(
5666
createConfig({

src/sandbox-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ export class SandboxClient {
266266
// Always add the "sdk" tag to the sandbox, this is used to identify sandboxes created by the SDK.
267267
const tagsWithSdk = tags.includes("sdk") ? tags : [...tags, "sdk"];
268268

269-
console.log(opts?.autoConnect === false ? undefined : startOptionsFromOpts(opts))
270269
const result = await sandboxFork({
271270
client: this.apiClient,
272271
body: {
@@ -276,7 +275,9 @@ export class SandboxClient {
276275
tags: tagsWithSdk,
277276
path,
278277
start_options:
279-
opts?.autoConnect === false ? undefined : startOptionsFromOpts(opts || {}),
278+
opts?.autoConnect === false
279+
? undefined
280+
: startOptionsFromOpts(opts || {}),
280281
},
281282
path: {
282283
id: typeof templateId === "string" ? templateId : templateId.id,

0 commit comments

Comments
 (0)