@sintaksdev/sdk 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -36,13 +36,18 @@ for await (const chunk of stream) {
36
36
 
37
37
  // Image generation
38
38
  const images = await client.images.generate({
39
- model: "flux-schnell",
40
39
  prompt: "A futuristic Jakarta skyline at dusk",
41
40
  });
42
41
  console.log(images.data[0]?.url);
42
+
43
+ // List active models
44
+ const models = await client.models.list();
45
+ console.log(models.data.map((m) => m.id));
43
46
  ```
44
47
 
45
- `model` defaults to `claude-sonnet-5-5` when omitted. Point at another environment with `baseURL`:
48
+ `model` defaults to `claude-sonnet-5-5` for chat and `stable-image-core` for
49
+ images when omitted. Streaming requests ask for `stream_options.include_usage`,
50
+ so the final chunk carries `usage`. Point at another environment with `baseURL`:
46
51
 
47
52
  ```ts
48
53
  const client = new Sintaks({ apiKey: "sk-...", baseURL: "http://localhost:8080" });
@@ -50,14 +55,16 @@ const client = new Sintaks({ apiKey: "sk-...", baseURL: "http://localhost:8080"
50
55
 
51
56
  ## Errors
52
57
 
53
- Failures throw `SintaksError` with `status`, `type`, `code`, and `requestId` (the gateway `X-Request-ID`, useful for support).
58
+ Failures throw `SintaksError` with `status`, `type`, `code`, and `requestId` (the gateway `X-Request-ID`, useful for support). Convenience getters map the gateway's status semantics:
54
59
 
55
60
  ```ts
56
61
  try {
57
62
  await client.chat.completions.create({ messages: [{ role: "user", content: "x" }] });
58
63
  } catch (err) {
59
- if (err instanceof SintaksError && err.status === 402) {
60
- console.error("insufficient balance, top up first");
64
+ if (err instanceof SintaksError) {
65
+ if (err.isUnauthorized) console.error("invalid or revoked api key");
66
+ if (err.isInsufficientCredits) console.error("insufficient balance, top up first");
67
+ if (err.isRetryable) console.error(`retry after ${err.requestId}`);
61
68
  }
62
69
  }
63
70
  ```
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
24
24
  DEFAULT_CHAT_MODEL: () => DEFAULT_CHAT_MODEL,
25
+ DEFAULT_IMAGE_MODEL: () => DEFAULT_IMAGE_MODEL,
25
26
  Sintaks: () => Sintaks,
26
27
  SintaksError: () => SintaksError,
27
28
  default: () => index_default
@@ -29,6 +30,7 @@ __export(index_exports, {
29
30
  module.exports = __toCommonJS(index_exports);
30
31
  var DEFAULT_BASE_URL = "https://api.sintaks.dev";
31
32
  var DEFAULT_CHAT_MODEL = "claude-sonnet-5-5";
33
+ var DEFAULT_IMAGE_MODEL = "stable-image-core";
32
34
  var SintaksError = class extends Error {
33
35
  status;
34
36
  type;
@@ -42,12 +44,29 @@ var SintaksError = class extends Error {
42
44
  this.code = opts.code ?? null;
43
45
  this.requestId = opts.requestId ?? null;
44
46
  }
47
+ /** True for missing, malformed, revoked, or invalid API keys (401). */
48
+ get isUnauthorized() {
49
+ return this.status === 401;
50
+ }
51
+ /** True when the account balance can't cover the request (402). Top up first. */
52
+ get isInsufficientCredits() {
53
+ return this.status === 402;
54
+ }
55
+ /** True for upstream throttling (429). */
56
+ get isRateLimited() {
57
+ return this.status === 429;
58
+ }
59
+ /** True for errors worth retrying with backoff: 429, 503, 504. */
60
+ get isRetryable() {
61
+ return this.status === 429 || this.status === 503 || this.status === 504;
62
+ }
45
63
  };
46
64
  var Sintaks = class {
47
65
  apiKey;
48
66
  baseURL;
49
67
  chat;
50
68
  images;
69
+ models;
51
70
  /** @internal */
52
71
  fetchFn;
53
72
  /** @internal */
@@ -60,6 +79,7 @@ var Sintaks = class {
60
79
  this.extraHeaders = options.headers ?? {};
61
80
  this.chat = new ChatResource(this);
62
81
  this.images = new ImagesResource(this);
82
+ this.models = new ModelsResource(this);
63
83
  }
64
84
  async request(method, path, body) {
65
85
  const res = await this.fetchFn(`${this.baseURL}${path}`, {
@@ -110,7 +130,11 @@ var ChatResource = class {
110
130
  Accept: "text/event-stream",
111
131
  ...this.client.extraHeaders
112
132
  },
113
- body: JSON.stringify({ ...params, model: params.model ?? DEFAULT_CHAT_MODEL })
133
+ body: JSON.stringify({
134
+ ...params,
135
+ model: params.model ?? DEFAULT_CHAT_MODEL,
136
+ stream_options: { include_usage: true }
137
+ })
114
138
  });
115
139
  if (!res.ok || !res.body) {
116
140
  let envelope = {};
@@ -160,7 +184,20 @@ var ImagesResource = class {
160
184
  }
161
185
  client;
162
186
  async generate(params) {
163
- return this.client.request("POST", "/v1/images/generations", params);
187
+ return this.client.request("POST", "/v1/images/generations", {
188
+ ...params,
189
+ model: params.model ?? DEFAULT_IMAGE_MODEL
190
+ });
191
+ }
192
+ };
193
+ var ModelsResource = class {
194
+ constructor(client) {
195
+ this.client = client;
196
+ }
197
+ client;
198
+ /** Lists the active models served by the gateway (GET /v1/models). */
199
+ async list() {
200
+ return this.client.request("GET", "/v1/models");
164
201
  }
165
202
  };
166
203
  var index_default = Sintaks;
@@ -168,6 +205,7 @@ var index_default = Sintaks;
168
205
  0 && (module.exports = {
169
206
  DEFAULT_BASE_URL,
170
207
  DEFAULT_CHAT_MODEL,
208
+ DEFAULT_IMAGE_MODEL,
171
209
  Sintaks,
172
210
  SintaksError
173
211
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @sintaksdev/sdk — TypeScript client for the sintaks.dev OpenAI-compatible\n * AI API gateway. Zero runtime dependencies; requires Node >= 18 (global fetch).\n */\n\nexport const DEFAULT_BASE_URL = \"https://api.sintaks.dev\";\nexport const DEFAULT_CHAT_MODEL = \"claude-sonnet-5-5\";\n\n/* ------------------------------------------------------------------ */\n/* Types (OpenAI-compatible shapes) */\n/* ------------------------------------------------------------------ */\n\nexport interface ChatMessage {\n role: \"system\" | \"user\" | \"assistant\" | \"tool\";\n content: string;\n name?: string;\n}\n\nexport interface ChatCompletionCreateParams {\n model?: string;\n messages: ChatMessage[];\n stream?: boolean;\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n stop?: string | string[];\n [key: string]: unknown;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: \"chat.completion\";\n created: number;\n model: string;\n choices: {\n index: number;\n message: ChatMessage;\n finish_reason: string | null;\n }[];\n usage?: {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n };\n}\n\nexport interface ChatCompletionChunk {\n id: string;\n object: \"chat.completion.chunk\";\n created: number;\n model: string;\n choices: {\n index: number;\n delta: { role?: string; content?: string | null };\n finish_reason: string | null;\n }[];\n}\n\nexport interface ImageGenerationParams {\n model?: string;\n prompt: string;\n n?: number;\n size?: string;\n [key: string]: unknown;\n}\n\nexport interface GeneratedImage {\n url?: string;\n b64_json?: string;\n}\n\nexport interface ImageGenerationResult {\n created: number;\n data: GeneratedImage[];\n}\n\nexport interface ErrorEnvelope {\n error?: {\n message?: string;\n type?: string;\n param?: string | null;\n code?: string | null;\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Error */\n/* ------------------------------------------------------------------ */\n\nexport class SintaksError extends Error {\n readonly status: number;\n readonly type: string | undefined;\n readonly code: string | null;\n readonly requestId: string | null;\n\n constructor(\n status: number,\n message: string,\n opts: { type?: string; code?: string | null; requestId?: string | null } = {},\n ) {\n super(message);\n this.name = \"SintaksError\";\n this.status = status;\n this.type = opts.type;\n this.code = opts.code ?? null;\n this.requestId = opts.requestId ?? null;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Client */\n/* ------------------------------------------------------------------ */\n\nexport interface SintaksOptions {\n apiKey: string;\n baseURL?: string;\n fetch?: typeof fetch;\n headers?: Record<string, string>;\n}\n\nexport class Sintaks {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly chat: ChatResource;\n readonly images: ImagesResource;\n\n /** @internal */\n readonly fetchFn: typeof fetch;\n /** @internal */\n readonly extraHeaders: Record<string, string>;\n\n constructor(options: SintaksOptions) {\n if (!options.apiKey) throw new Error(\"Sintaks: apiKey is required\");\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = options.fetch ?? fetch;\n this.extraHeaders = options.headers ?? {};\n this.chat = new ChatResource(this);\n this.images = new ImagesResource(this);\n }\n\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await this.fetchFn(`${this.baseURL}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...this.extraHeaders,\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!res.ok) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // non-JSON error body; fall through with defaults\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n return (await res.json()) as T;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Chat */\n/* ------------------------------------------------------------------ */\n\nclass ChatResource {\n readonly completions = this;\n\n constructor(private client: Sintaks) {}\n\n async create(params: ChatCompletionCreateParams): Promise<ChatCompletion>;\n async create(params: ChatCompletionCreateParams & { stream: true }): Promise<AsyncIterable<ChatCompletionChunk>>;\n async create(\n params: ChatCompletionCreateParams,\n ): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>> {\n if (params.stream) {\n return this.createStream(params as ChatCompletionCreateParams & { stream: true });\n }\n return this.client.request<ChatCompletion>(\"POST\", \"/v1/chat/completions\", {\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n });\n }\n\n private async createStream(\n params: ChatCompletionCreateParams & { stream: true },\n ): Promise<AsyncIterable<ChatCompletionChunk>> {\n const res = await this.client.fetchFn(`${this.client.baseURL}/v1/chat/completions`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.client.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n ...this.client.extraHeaders,\n },\n body: JSON.stringify({ ...params, model: params.model ?? DEFAULT_CHAT_MODEL }),\n });\n\n if (!res.ok || !res.body) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // ignore\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n\n return parseSSE<ChatCompletionChunk>(res.body);\n }\n}\n\n/** Minimal SSE parser for OpenAI-style `data:` events. */\nasync function* parseSSE<T>(body: ReadableStream<Uint8Array>): AsyncIterable<T> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let boundary: number;\n while ((boundary = buffer.indexOf(\"\\n\\n\")) !== -1) {\n const chunk = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n const dataLine = chunk\n .split(\"\\n\")\n .find((line) => line.startsWith(\"data:\"));\n if (!dataLine) continue;\n const payload = dataLine.slice(5).trim();\n if (payload === \"[DONE]\") return;\n try {\n yield JSON.parse(payload) as T;\n } catch {\n // skip malformed event\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Images */\n/* ------------------------------------------------------------------ */\n\nclass ImagesResource {\n constructor(private client: Sintaks) {}\n\n async generate(params: ImageGenerationParams): Promise<ImageGenerationResult> {\n return this.client.request<ImageGenerationResult>(\"POST\", \"/v1/images/generations\", params);\n }\n}\n\nexport default Sintaks;"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAmF3B,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,QACA,SACA,OAA2E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AM,UAAU,IAAI,YAAY;AAChC,MAAI,SAAS;AAEb,MAAI;AACF,WAAO,MAAM;AACX,YAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,gBAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAEhD,UAAI;AACJ,cAAQ,WAAW,OAAO,QAAQ,MAAM,OAAO,IAAI;AACjD,cAAM,QAAQ,OAAO,MAAM,GAAG,QAAQ;AACtC,iBAAS,OAAO,MAAM,WAAW,CAAC;AAClC,cAAM,WAAW,MACd,MAAM,IAAI,EACV,KAAK,CAAC,SAAS,KAAK,WAAW,OAAO,CAAC;AAC1C,YAAI,CAAC,SAAU;AACf,cAAM,UAAU,SAAS,MAAM,CAAC,EAAE,KAAK;AACvC,YAAI,YAAY,SAAU;AAC1B,YAAI;AACF,gBAAM,KAAK,MAAM,OAAO;AAAA,QAC1B,QAAQ;AAAA,QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;AAMA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAAoB,QAAiB;AAAjB;AAAA,EAAkB;AAAA,EAAlB;AAAA,EAEpB,MAAM,SAAS,QAA+D;AAC5E,WAAO,KAAK,OAAO,QAA+B,QAAQ,0BAA0B,MAAM;AAAA,EAC5F;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @sintaksdev/sdk — TypeScript client for the sintaks.dev OpenAI-compatible\n * AI API gateway. Zero runtime dependencies; requires Node >= 18 (global fetch).\n */\n\nexport const DEFAULT_BASE_URL = \"https://api.sintaks.dev\";\nexport const DEFAULT_CHAT_MODEL = \"claude-sonnet-5-5\";\nexport const DEFAULT_IMAGE_MODEL = \"stable-image-core\";\n\n/* ------------------------------------------------------------------ */\n/* Types (OpenAI-compatible shapes) */\n/* ------------------------------------------------------------------ */\n\nexport type MessageContentPart = { type: \"text\"; text: string };\n\nexport interface ChatMessage {\n role: \"system\" | \"developer\" | \"user\" | \"assistant\" | \"tool\";\n content: string | MessageContentPart[];\n name?: string;\n}\n\nexport interface ChatCompletionCreateParams {\n model?: string;\n messages: ChatMessage[];\n stream?: boolean;\n stream_options?: { include_usage?: boolean };\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n max_completion_tokens?: number;\n stop?: string | string[];\n [key: string]: unknown;\n}\n\nexport interface Usage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: \"chat.completion\";\n created: number;\n model: string;\n choices: {\n index: number;\n message: ChatMessage;\n finish_reason: string | null;\n }[];\n usage?: Usage;\n}\n\nexport interface ChatCompletionChunk {\n id: string;\n object: \"chat.completion.chunk\";\n created: number;\n model: string;\n choices: {\n index: number;\n delta: { role?: string; content?: string | null };\n finish_reason: string | null;\n }[];\n usage?: Usage;\n}\n\nexport interface Model {\n id: string;\n object: \"model\";\n created: number;\n owned_by: string;\n}\n\nexport interface ModelList {\n object: \"list\";\n data: Model[];\n}\n\nexport interface ImageGenerationParams {\n model?: string;\n prompt: string;\n n?: number;\n size?: string;\n [key: string]: unknown;\n}\n\nexport interface GeneratedImage {\n url?: string;\n b64_json?: string;\n}\n\nexport interface ImageGenerationResult {\n created: number;\n data: GeneratedImage[];\n}\n\nexport interface ErrorEnvelope {\n error?: {\n message?: string;\n type?: string;\n param?: string | null;\n code?: string | null;\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Error */\n/* ------------------------------------------------------------------ */\n\nexport class SintaksError extends Error {\n readonly status: number;\n readonly type: string | undefined;\n readonly code: string | null;\n readonly requestId: string | null;\n\n constructor(\n status: number,\n message: string,\n opts: { type?: string; code?: string | null; requestId?: string | null } = {},\n ) {\n super(message);\n this.name = \"SintaksError\";\n this.status = status;\n this.type = opts.type;\n this.code = opts.code ?? null;\n this.requestId = opts.requestId ?? null;\n }\n\n /** True for missing, malformed, revoked, or invalid API keys (401). */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** True when the account balance can't cover the request (402). Top up first. */\n get isInsufficientCredits(): boolean {\n return this.status === 402;\n }\n\n /** True for upstream throttling (429). */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** True for errors worth retrying with backoff: 429, 503, 504. */\n get isRetryable(): boolean {\n return this.status === 429 || this.status === 503 || this.status === 504;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Client */\n/* ------------------------------------------------------------------ */\n\nexport interface SintaksOptions {\n apiKey: string;\n baseURL?: string;\n fetch?: typeof fetch;\n headers?: Record<string, string>;\n}\n\nexport class Sintaks {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly chat: ChatResource;\n readonly images: ImagesResource;\n readonly models: ModelsResource;\n\n /** @internal */\n readonly fetchFn: typeof fetch;\n /** @internal */\n readonly extraHeaders: Record<string, string>;\n\n constructor(options: SintaksOptions) {\n if (!options.apiKey) throw new Error(\"Sintaks: apiKey is required\");\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = options.fetch ?? fetch;\n this.extraHeaders = options.headers ?? {};\n this.chat = new ChatResource(this);\n this.images = new ImagesResource(this);\n this.models = new ModelsResource(this);\n }\n\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await this.fetchFn(`${this.baseURL}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...this.extraHeaders,\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!res.ok) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // non-JSON error body; fall through with defaults\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n return (await res.json()) as T;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Chat */\n/* ------------------------------------------------------------------ */\n\nclass ChatResource {\n readonly completions = this;\n\n constructor(private client: Sintaks) {}\n\n async create(params: ChatCompletionCreateParams): Promise<ChatCompletion>;\n async create(params: ChatCompletionCreateParams & { stream: true }): Promise<AsyncIterable<ChatCompletionChunk>>;\n async create(\n params: ChatCompletionCreateParams,\n ): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>> {\n if (params.stream) {\n return this.createStream(params as ChatCompletionCreateParams & { stream: true });\n }\n return this.client.request<ChatCompletion>(\"POST\", \"/v1/chat/completions\", {\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n });\n }\n\n private async createStream(\n params: ChatCompletionCreateParams & { stream: true },\n ): Promise<AsyncIterable<ChatCompletionChunk>> {\n const res = await this.client.fetchFn(`${this.client.baseURL}/v1/chat/completions`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.client.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n ...this.client.extraHeaders,\n },\n body: JSON.stringify({\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n stream_options: { include_usage: true },\n }),\n });\n\n if (!res.ok || !res.body) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // ignore\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n\n return parseSSE<ChatCompletionChunk>(res.body);\n }\n}\n\n/** Minimal SSE parser for OpenAI-style `data:` events. */\nasync function* parseSSE<T>(body: ReadableStream<Uint8Array>): AsyncIterable<T> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let boundary: number;\n while ((boundary = buffer.indexOf(\"\\n\\n\")) !== -1) {\n const chunk = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n const dataLine = chunk\n .split(\"\\n\")\n .find((line) => line.startsWith(\"data:\"));\n if (!dataLine) continue;\n const payload = dataLine.slice(5).trim();\n if (payload === \"[DONE]\") return;\n try {\n yield JSON.parse(payload) as T;\n } catch {\n // skip malformed event\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Images */\n/* ------------------------------------------------------------------ */\n\nclass ImagesResource {\n constructor(private client: Sintaks) {}\n\n async generate(params: ImageGenerationParams): Promise<ImageGenerationResult> {\n return this.client.request<ImageGenerationResult>(\"POST\", \"/v1/images/generations\", {\n ...params,\n model: params.model ?? DEFAULT_IMAGE_MODEL,\n });\n }\n}\n\nclass ModelsResource {\n constructor(private client: Sintaks) {}\n\n /** Lists the active models served by the gateway (GET /v1/models). */\n async list(): Promise<ModelList> {\n return this.client.request<ModelList>(\"GET\", \"/v1/models\");\n }\n}\n\nexport default Sintaks;"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAC3B,IAAM,sBAAsB;AAsG5B,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,QACA,SACA,OAA2E,CAAC,GAC5E;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,KAAK;AACjB,SAAK,OAAO,KAAK,QAAQ;AACzB,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AAAA;AAAA,EAGA,IAAI,iBAA0B;AAC5B,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA;AAAA,EAGA,IAAI,wBAAiC;AACnC,WAAO,KAAK,WAAW;AAAA,EACzB;AAAA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ist/index.d.cts CHANGED
@@ -4,21 +4,35 @@
4
4
  */
5
5
  declare const DEFAULT_BASE_URL = "https://api.sintaks.dev";
6
6
  declare const DEFAULT_CHAT_MODEL = "claude-sonnet-5-5";
7
+ declare const DEFAULT_IMAGE_MODEL = "stable-image-core";
8
+ type MessageContentPart = {
9
+ type: "text";
10
+ text: string;
11
+ };
7
12
  interface ChatMessage {
8
- role: "system" | "user" | "assistant" | "tool";
9
- content: string;
13
+ role: "system" | "developer" | "user" | "assistant" | "tool";
14
+ content: string | MessageContentPart[];
10
15
  name?: string;
11
16
  }
12
17
  interface ChatCompletionCreateParams {
13
18
  model?: string;
14
19
  messages: ChatMessage[];
15
20
  stream?: boolean;
21
+ stream_options?: {
22
+ include_usage?: boolean;
23
+ };
16
24
  temperature?: number;
17
25
  top_p?: number;
18
26
  max_tokens?: number;
27
+ max_completion_tokens?: number;
19
28
  stop?: string | string[];
20
29
  [key: string]: unknown;
21
30
  }
31
+ interface Usage {
32
+ prompt_tokens: number;
33
+ completion_tokens: number;
34
+ total_tokens: number;
35
+ }
22
36
  interface ChatCompletion {
23
37
  id: string;
24
38
  object: "chat.completion";
@@ -29,11 +43,7 @@ interface ChatCompletion {
29
43
  message: ChatMessage;
30
44
  finish_reason: string | null;
31
45
  }[];
32
- usage?: {
33
- prompt_tokens: number;
34
- completion_tokens: number;
35
- total_tokens: number;
36
- };
46
+ usage?: Usage;
37
47
  }
38
48
  interface ChatCompletionChunk {
39
49
  id: string;
@@ -48,6 +58,17 @@ interface ChatCompletionChunk {
48
58
  };
49
59
  finish_reason: string | null;
50
60
  }[];
61
+ usage?: Usage;
62
+ }
63
+ interface Model {
64
+ id: string;
65
+ object: "model";
66
+ created: number;
67
+ owned_by: string;
68
+ }
69
+ interface ModelList {
70
+ object: "list";
71
+ data: Model[];
51
72
  }
52
73
  interface ImageGenerationParams {
53
74
  model?: string;
@@ -82,6 +103,14 @@ declare class SintaksError extends Error {
82
103
  code?: string | null;
83
104
  requestId?: string | null;
84
105
  });
106
+ /** True for missing, malformed, revoked, or invalid API keys (401). */
107
+ get isUnauthorized(): boolean;
108
+ /** True when the account balance can't cover the request (402). Top up first. */
109
+ get isInsufficientCredits(): boolean;
110
+ /** True for upstream throttling (429). */
111
+ get isRateLimited(): boolean;
112
+ /** True for errors worth retrying with backoff: 429, 503, 504. */
113
+ get isRetryable(): boolean;
85
114
  }
86
115
  interface SintaksOptions {
87
116
  apiKey: string;
@@ -94,6 +123,7 @@ declare class Sintaks {
94
123
  readonly baseURL: string;
95
124
  readonly chat: ChatResource;
96
125
  readonly images: ImagesResource;
126
+ readonly models: ModelsResource;
97
127
  /** @internal */
98
128
  readonly fetchFn: typeof fetch;
99
129
  /** @internal */
@@ -116,5 +146,11 @@ declare class ImagesResource {
116
146
  constructor(client: Sintaks);
117
147
  generate(params: ImageGenerationParams): Promise<ImageGenerationResult>;
118
148
  }
149
+ declare class ModelsResource {
150
+ private client;
151
+ constructor(client: Sintaks);
152
+ /** Lists the active models served by the gateway (GET /v1/models). */
153
+ list(): Promise<ModelList>;
154
+ }
119
155
 
120
- export { type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, DEFAULT_BASE_URL, DEFAULT_CHAT_MODEL, type ErrorEnvelope, type GeneratedImage, type ImageGenerationParams, type ImageGenerationResult, Sintaks, SintaksError, type SintaksOptions, Sintaks as default };
156
+ export { type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, DEFAULT_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_IMAGE_MODEL, type ErrorEnvelope, type GeneratedImage, type ImageGenerationParams, type ImageGenerationResult, type MessageContentPart, type Model, type ModelList, Sintaks, SintaksError, type SintaksOptions, type Usage, Sintaks as default };
package/dist/index.d.ts CHANGED
@@ -4,21 +4,35 @@
4
4
  */
5
5
  declare const DEFAULT_BASE_URL = "https://api.sintaks.dev";
6
6
  declare const DEFAULT_CHAT_MODEL = "claude-sonnet-5-5";
7
+ declare const DEFAULT_IMAGE_MODEL = "stable-image-core";
8
+ type MessageContentPart = {
9
+ type: "text";
10
+ text: string;
11
+ };
7
12
  interface ChatMessage {
8
- role: "system" | "user" | "assistant" | "tool";
9
- content: string;
13
+ role: "system" | "developer" | "user" | "assistant" | "tool";
14
+ content: string | MessageContentPart[];
10
15
  name?: string;
11
16
  }
12
17
  interface ChatCompletionCreateParams {
13
18
  model?: string;
14
19
  messages: ChatMessage[];
15
20
  stream?: boolean;
21
+ stream_options?: {
22
+ include_usage?: boolean;
23
+ };
16
24
  temperature?: number;
17
25
  top_p?: number;
18
26
  max_tokens?: number;
27
+ max_completion_tokens?: number;
19
28
  stop?: string | string[];
20
29
  [key: string]: unknown;
21
30
  }
31
+ interface Usage {
32
+ prompt_tokens: number;
33
+ completion_tokens: number;
34
+ total_tokens: number;
35
+ }
22
36
  interface ChatCompletion {
23
37
  id: string;
24
38
  object: "chat.completion";
@@ -29,11 +43,7 @@ interface ChatCompletion {
29
43
  message: ChatMessage;
30
44
  finish_reason: string | null;
31
45
  }[];
32
- usage?: {
33
- prompt_tokens: number;
34
- completion_tokens: number;
35
- total_tokens: number;
36
- };
46
+ usage?: Usage;
37
47
  }
38
48
  interface ChatCompletionChunk {
39
49
  id: string;
@@ -48,6 +58,17 @@ interface ChatCompletionChunk {
48
58
  };
49
59
  finish_reason: string | null;
50
60
  }[];
61
+ usage?: Usage;
62
+ }
63
+ interface Model {
64
+ id: string;
65
+ object: "model";
66
+ created: number;
67
+ owned_by: string;
68
+ }
69
+ interface ModelList {
70
+ object: "list";
71
+ data: Model[];
51
72
  }
52
73
  interface ImageGenerationParams {
53
74
  model?: string;
@@ -82,6 +103,14 @@ declare class SintaksError extends Error {
82
103
  code?: string | null;
83
104
  requestId?: string | null;
84
105
  });
106
+ /** True for missing, malformed, revoked, or invalid API keys (401). */
107
+ get isUnauthorized(): boolean;
108
+ /** True when the account balance can't cover the request (402). Top up first. */
109
+ get isInsufficientCredits(): boolean;
110
+ /** True for upstream throttling (429). */
111
+ get isRateLimited(): boolean;
112
+ /** True for errors worth retrying with backoff: 429, 503, 504. */
113
+ get isRetryable(): boolean;
85
114
  }
86
115
  interface SintaksOptions {
87
116
  apiKey: string;
@@ -94,6 +123,7 @@ declare class Sintaks {
94
123
  readonly baseURL: string;
95
124
  readonly chat: ChatResource;
96
125
  readonly images: ImagesResource;
126
+ readonly models: ModelsResource;
97
127
  /** @internal */
98
128
  readonly fetchFn: typeof fetch;
99
129
  /** @internal */
@@ -116,5 +146,11 @@ declare class ImagesResource {
116
146
  constructor(client: Sintaks);
117
147
  generate(params: ImageGenerationParams): Promise<ImageGenerationResult>;
118
148
  }
149
+ declare class ModelsResource {
150
+ private client;
151
+ constructor(client: Sintaks);
152
+ /** Lists the active models served by the gateway (GET /v1/models). */
153
+ list(): Promise<ModelList>;
154
+ }
119
155
 
120
- export { type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, DEFAULT_BASE_URL, DEFAULT_CHAT_MODEL, type ErrorEnvelope, type GeneratedImage, type ImageGenerationParams, type ImageGenerationResult, Sintaks, SintaksError, type SintaksOptions, Sintaks as default };
156
+ export { type ChatCompletion, type ChatCompletionChunk, type ChatCompletionCreateParams, type ChatMessage, DEFAULT_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_IMAGE_MODEL, type ErrorEnvelope, type GeneratedImage, type ImageGenerationParams, type ImageGenerationResult, type MessageContentPart, type Model, type ModelList, Sintaks, SintaksError, type SintaksOptions, type Usage, Sintaks as default };
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
  var DEFAULT_BASE_URL = "https://api.sintaks.dev";
3
3
  var DEFAULT_CHAT_MODEL = "claude-sonnet-5-5";
4
+ var DEFAULT_IMAGE_MODEL = "stable-image-core";
4
5
  var SintaksError = class extends Error {
5
6
  status;
6
7
  type;
@@ -14,12 +15,29 @@ var SintaksError = class extends Error {
14
15
  this.code = opts.code ?? null;
15
16
  this.requestId = opts.requestId ?? null;
16
17
  }
18
+ /** True for missing, malformed, revoked, or invalid API keys (401). */
19
+ get isUnauthorized() {
20
+ return this.status === 401;
21
+ }
22
+ /** True when the account balance can't cover the request (402). Top up first. */
23
+ get isInsufficientCredits() {
24
+ return this.status === 402;
25
+ }
26
+ /** True for upstream throttling (429). */
27
+ get isRateLimited() {
28
+ return this.status === 429;
29
+ }
30
+ /** True for errors worth retrying with backoff: 429, 503, 504. */
31
+ get isRetryable() {
32
+ return this.status === 429 || this.status === 503 || this.status === 504;
33
+ }
17
34
  };
18
35
  var Sintaks = class {
19
36
  apiKey;
20
37
  baseURL;
21
38
  chat;
22
39
  images;
40
+ models;
23
41
  /** @internal */
24
42
  fetchFn;
25
43
  /** @internal */
@@ -32,6 +50,7 @@ var Sintaks = class {
32
50
  this.extraHeaders = options.headers ?? {};
33
51
  this.chat = new ChatResource(this);
34
52
  this.images = new ImagesResource(this);
53
+ this.models = new ModelsResource(this);
35
54
  }
36
55
  async request(method, path, body) {
37
56
  const res = await this.fetchFn(`${this.baseURL}${path}`, {
@@ -82,7 +101,11 @@ var ChatResource = class {
82
101
  Accept: "text/event-stream",
83
102
  ...this.client.extraHeaders
84
103
  },
85
- body: JSON.stringify({ ...params, model: params.model ?? DEFAULT_CHAT_MODEL })
104
+ body: JSON.stringify({
105
+ ...params,
106
+ model: params.model ?? DEFAULT_CHAT_MODEL,
107
+ stream_options: { include_usage: true }
108
+ })
86
109
  });
87
110
  if (!res.ok || !res.body) {
88
111
  let envelope = {};
@@ -132,13 +155,27 @@ var ImagesResource = class {
132
155
  }
133
156
  client;
134
157
  async generate(params) {
135
- return this.client.request("POST", "/v1/images/generations", params);
158
+ return this.client.request("POST", "/v1/images/generations", {
159
+ ...params,
160
+ model: params.model ?? DEFAULT_IMAGE_MODEL
161
+ });
162
+ }
163
+ };
164
+ var ModelsResource = class {
165
+ constructor(client) {
166
+ this.client = client;
167
+ }
168
+ client;
169
+ /** Lists the active models served by the gateway (GET /v1/models). */
170
+ async list() {
171
+ return this.client.request("GET", "/v1/models");
136
172
  }
137
173
  };
138
174
  var index_default = Sintaks;
139
175
  export {
140
176
  DEFAULT_BASE_URL,
141
177
  DEFAULT_CHAT_MODEL,
178
+ DEFAULT_IMAGE_MODEL,
142
179
  Sintaks,
143
180
  SintaksError,
144
181
  index_default as default
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @sintaksdev/sdk — TypeScript client for the sintaks.dev OpenAI-compatible\n * AI API gateway. Zero runtime dependencies; requires Node >= 18 (global fetch).\n */\n\nexport const DEFAULT_BASE_URL = \"https://api.sintaks.dev\";\nexport const DEFAULT_CHAT_MODEL = \"claude-sonnet-5-5\";\n\n/* ------------------------------------------------------------------ */\n/* Types (OpenAI-compatible shapes) */\n/* ------------------------------------------------------------------ */\n\nexport interface ChatMessage {\n role: \"system\" | \"user\" | \"assistant\" | \"tool\";\n content: string;\n name?: string;\n}\n\nexport interface ChatCompletionCreateParams {\n model?: string;\n messages: ChatMessage[];\n stream?: boolean;\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n stop?: string | string[];\n [key: string]: unknown;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: \"chat.completion\";\n created: number;\n model: string;\n choices: {\n index: number;\n message: ChatMessage;\n finish_reason: string | null;\n }[];\n usage?: {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n };\n}\n\nexport interface ChatCompletionChunk {\n id: string;\n object: \"chat.completion.chunk\";\n created: number;\n model: string;\n choices: {\n index: number;\n delta: { role?: string; content?: string | null };\n finish_reason: string | null;\n }[];\n}\n\nexport interface ImageGenerationParams {\n model?: string;\n prompt: string;\n n?: number;\n size?: string;\n [key: string]: unknown;\n}\n\nexport interface GeneratedImage {\n url?: string;\n b64_json?: string;\n}\n\nexport interface ImageGenerationResult {\n created: number;\n data: GeneratedImage[];\n}\n\nexport interface ErrorEnvelope {\n error?: {\n message?: string;\n type?: string;\n param?: string | null;\n code?: string | null;\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Error */\n/* ------------------------------------------------------------------ */\n\nexport class SintaksError extends Error {\n readonly status: number;\n readonly type: string | undefined;\n readonly code: string | null;\n readonly requestId: string | null;\n\n constructor(\n status: number,\n message: string,\n opts: { type?: string; code?: string | null; requestId?: string | null } = {},\n ) {\n super(message);\n this.name = \"SintaksError\";\n this.status = status;\n this.type = opts.type;\n this.code = opts.code ?? null;\n this.requestId = opts.requestId ?? null;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Client */\n/* ------------------------------------------------------------------ */\n\nexport interface SintaksOptions {\n apiKey: string;\n baseURL?: string;\n fetch?: typeof fetch;\n headers?: Record<string, string>;\n}\n\nexport class Sintaks {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly chat: ChatResource;\n readonly images: ImagesResource;\n\n /** @internal */\n readonly fetchFn: typeof fetch;\n /** @internal */\n readonly extraHeaders: Record<string, string>;\n\n constructor(options: SintaksOptions) {\n if (!options.apiKey) throw new Error(\"Sintaks: apiKey is required\");\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = options.fetch ?? fetch;\n this.extraHeaders = options.headers ?? {};\n this.chat = new ChatResource(this);\n this.images = new ImagesResource(this);\n }\n\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await this.fetchFn(`${this.baseURL}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...this.extraHeaders,\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!res.ok) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // non-JSON error body; fall through with defaults\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n return (await res.json()) as T;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Chat */\n/* ------------------------------------------------------------------ */\n\nclass ChatResource {\n readonly completions = this;\n\n constructor(private client: Sintaks) {}\n\n async create(params: ChatCompletionCreateParams): Promise<ChatCompletion>;\n async create(params: ChatCompletionCreateParams & { stream: true }): Promise<AsyncIterable<ChatCompletionChunk>>;\n async create(\n params: ChatCompletionCreateParams,\n ): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>> {\n if (params.stream) {\n return this.createStream(params as ChatCompletionCreateParams & { stream: true });\n }\n return this.client.request<ChatCompletion>(\"POST\", \"/v1/chat/completions\", {\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n });\n }\n\n private async createStream(\n params: ChatCompletionCreateParams & { stream: true },\n ): Promise<AsyncIterable<ChatCompletionChunk>> {\n const res = await this.client.fetchFn(`${this.client.baseURL}/v1/chat/completions`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.client.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n ...this.client.extraHeaders,\n },\n body: JSON.stringify({ ...params, model: params.model ?? DEFAULT_CHAT_MODEL }),\n });\n\n if (!res.ok || !res.body) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // ignore\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n\n return parseSSE<ChatCompletionChunk>(res.body);\n }\n}\n\n/** Minimal SSE parser for OpenAI-style `data:` events. */\nasync function* parseSSE<T>(body: ReadableStream<Uint8Array>): AsyncIterable<T> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let boundary: number;\n while ((boundary = buffer.indexOf(\"\\n\\n\")) !== -1) {\n const chunk = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n const dataLine = chunk\n .split(\"\\n\")\n .find((line) => line.startsWith(\"data:\"));\n if (!dataLine) continue;\n const payload = dataLine.slice(5).trim();\n if (payload === \"[DONE]\") return;\n try {\n yield JSON.parse(payload) as T;\n } catch {\n // skip malformed event\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Images */\n/* ------------------------------------------------------------------ */\n\nclass ImagesResource {\n constructor(private client: Sintaks) {}\n\n async generate(params: ImageGenerationParams): Promise<ImageGenerationResult> {\n return this.client.request<ImageGenerationResult>(\"POST\", \"/v1/images/generations\", params);\n }\n}\n\nexport default Sintaks;"],"mappings":";AAKO,IAAM,mBAAmB;AACzB,IAAM,qBAAqB;AAmF3B,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YACE,QACA,SACA,OAA2E,CAAC,GAC5E;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO,KAAK;AACjB,SAAK,OAAO,KAAK,QAAQ;AACzB,SAAK,YAAY,KAAK,aAAa;AAAA,EACrC;AACF;AAaO,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAGA;AAAA;AAAA,EAEA;AAAA,EAET,YAAY,SAAyB;AACnC,QAAI,CAAC,QAAQ,OAAQ,OAAM,IAAI,MAAM,6BAA6B;AAClE,SAAK,SAAS,QAAQ;AACtB,SAAK,WAAW,QAAQ,WAAW,kBAAkB,QAAQ,QAAQ,EAAE;AACvE,SAAK,UAAU,QAAQ,SAAS;AAChC,SAAK,eAAe,QAAQ,WAAW,CAAC;AACxC,SAAK,OAAO,IAAI,aAAa,IAAI;AACjC,SAAK,SAAS,IAAI,eAAe,IAAI;AAAA,EACvC;AAAA,EAEA,MAAM,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A,IACF;AAAA,EACF,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;AAMA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAAoB,QAAiB;AAAjB;AAAA,EAAkB;AAAA,EAAlB;AAAA,EAEpB,MAAM,SAAS,QAA+D;AAC5E,WAAO,KAAK,OAAO,QAA+B,QAAQ,0BAA0B,MAAM;AAAA,EAC5F;AACF;AAEA,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @sintaksdev/sdk — TypeScript client for the sintaks.dev OpenAI-compatible\n * AI API gateway. Zero runtime dependencies; requires Node >= 18 (global fetch).\n */\n\nexport const DEFAULT_BASE_URL = \"https://api.sintaks.dev\";\nexport const DEFAULT_CHAT_MODEL = \"claude-sonnet-5-5\";\nexport const DEFAULT_IMAGE_MODEL = \"stable-image-core\";\n\n/* ------------------------------------------------------------------ */\n/* Types (OpenAI-compatible shapes) */\n/* ------------------------------------------------------------------ */\n\nexport type MessageContentPart = { type: \"text\"; text: string };\n\nexport interface ChatMessage {\n role: \"system\" | \"developer\" | \"user\" | \"assistant\" | \"tool\";\n content: string | MessageContentPart[];\n name?: string;\n}\n\nexport interface ChatCompletionCreateParams {\n model?: string;\n messages: ChatMessage[];\n stream?: boolean;\n stream_options?: { include_usage?: boolean };\n temperature?: number;\n top_p?: number;\n max_tokens?: number;\n max_completion_tokens?: number;\n stop?: string | string[];\n [key: string]: unknown;\n}\n\nexport interface Usage {\n prompt_tokens: number;\n completion_tokens: number;\n total_tokens: number;\n}\n\nexport interface ChatCompletion {\n id: string;\n object: \"chat.completion\";\n created: number;\n model: string;\n choices: {\n index: number;\n message: ChatMessage;\n finish_reason: string | null;\n }[];\n usage?: Usage;\n}\n\nexport interface ChatCompletionChunk {\n id: string;\n object: \"chat.completion.chunk\";\n created: number;\n model: string;\n choices: {\n index: number;\n delta: { role?: string; content?: string | null };\n finish_reason: string | null;\n }[];\n usage?: Usage;\n}\n\nexport interface Model {\n id: string;\n object: \"model\";\n created: number;\n owned_by: string;\n}\n\nexport interface ModelList {\n object: \"list\";\n data: Model[];\n}\n\nexport interface ImageGenerationParams {\n model?: string;\n prompt: string;\n n?: number;\n size?: string;\n [key: string]: unknown;\n}\n\nexport interface GeneratedImage {\n url?: string;\n b64_json?: string;\n}\n\nexport interface ImageGenerationResult {\n created: number;\n data: GeneratedImage[];\n}\n\nexport interface ErrorEnvelope {\n error?: {\n message?: string;\n type?: string;\n param?: string | null;\n code?: string | null;\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Error */\n/* ------------------------------------------------------------------ */\n\nexport class SintaksError extends Error {\n readonly status: number;\n readonly type: string | undefined;\n readonly code: string | null;\n readonly requestId: string | null;\n\n constructor(\n status: number,\n message: string,\n opts: { type?: string; code?: string | null; requestId?: string | null } = {},\n ) {\n super(message);\n this.name = \"SintaksError\";\n this.status = status;\n this.type = opts.type;\n this.code = opts.code ?? null;\n this.requestId = opts.requestId ?? null;\n }\n\n /** True for missing, malformed, revoked, or invalid API keys (401). */\n get isUnauthorized(): boolean {\n return this.status === 401;\n }\n\n /** True when the account balance can't cover the request (402). Top up first. */\n get isInsufficientCredits(): boolean {\n return this.status === 402;\n }\n\n /** True for upstream throttling (429). */\n get isRateLimited(): boolean {\n return this.status === 429;\n }\n\n /** True for errors worth retrying with backoff: 429, 503, 504. */\n get isRetryable(): boolean {\n return this.status === 429 || this.status === 503 || this.status === 504;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Client */\n/* ------------------------------------------------------------------ */\n\nexport interface SintaksOptions {\n apiKey: string;\n baseURL?: string;\n fetch?: typeof fetch;\n headers?: Record<string, string>;\n}\n\nexport class Sintaks {\n readonly apiKey: string;\n readonly baseURL: string;\n readonly chat: ChatResource;\n readonly images: ImagesResource;\n readonly models: ModelsResource;\n\n /** @internal */\n readonly fetchFn: typeof fetch;\n /** @internal */\n readonly extraHeaders: Record<string, string>;\n\n constructor(options: SintaksOptions) {\n if (!options.apiKey) throw new Error(\"Sintaks: apiKey is required\");\n this.apiKey = options.apiKey;\n this.baseURL = (options.baseURL ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.fetchFn = options.fetch ?? fetch;\n this.extraHeaders = options.headers ?? {};\n this.chat = new ChatResource(this);\n this.images = new ImagesResource(this);\n this.models = new ModelsResource(this);\n }\n\n async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const res = await this.fetchFn(`${this.baseURL}${path}`, {\n method,\n headers: {\n Authorization: `Bearer ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n ...this.extraHeaders,\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n });\n\n if (!res.ok) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // non-JSON error body; fall through with defaults\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n return (await res.json()) as T;\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Chat */\n/* ------------------------------------------------------------------ */\n\nclass ChatResource {\n readonly completions = this;\n\n constructor(private client: Sintaks) {}\n\n async create(params: ChatCompletionCreateParams): Promise<ChatCompletion>;\n async create(params: ChatCompletionCreateParams & { stream: true }): Promise<AsyncIterable<ChatCompletionChunk>>;\n async create(\n params: ChatCompletionCreateParams,\n ): Promise<ChatCompletion | AsyncIterable<ChatCompletionChunk>> {\n if (params.stream) {\n return this.createStream(params as ChatCompletionCreateParams & { stream: true });\n }\n return this.client.request<ChatCompletion>(\"POST\", \"/v1/chat/completions\", {\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n });\n }\n\n private async createStream(\n params: ChatCompletionCreateParams & { stream: true },\n ): Promise<AsyncIterable<ChatCompletionChunk>> {\n const res = await this.client.fetchFn(`${this.client.baseURL}/v1/chat/completions`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${this.client.apiKey}`,\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n ...this.client.extraHeaders,\n },\n body: JSON.stringify({\n ...params,\n model: params.model ?? DEFAULT_CHAT_MODEL,\n stream_options: { include_usage: true },\n }),\n });\n\n if (!res.ok || !res.body) {\n let envelope: ErrorEnvelope = {};\n try {\n envelope = (await res.json()) as ErrorEnvelope;\n } catch {\n // ignore\n }\n throw new SintaksError(res.status, envelope.error?.message ?? `request failed with ${res.status}`, {\n type: envelope.error?.type,\n code: envelope.error?.code,\n requestId: res.headers.get(\"x-request-id\"),\n });\n }\n\n return parseSSE<ChatCompletionChunk>(res.body);\n }\n}\n\n/** Minimal SSE parser for OpenAI-style `data:` events. */\nasync function* parseSSE<T>(body: ReadableStream<Uint8Array>): AsyncIterable<T> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n\n let boundary: number;\n while ((boundary = buffer.indexOf(\"\\n\\n\")) !== -1) {\n const chunk = buffer.slice(0, boundary);\n buffer = buffer.slice(boundary + 2);\n const dataLine = chunk\n .split(\"\\n\")\n .find((line) => line.startsWith(\"data:\"));\n if (!dataLine) continue;\n const payload = dataLine.slice(5).trim();\n if (payload === \"[DONE]\") return;\n try {\n yield JSON.parse(payload) as T;\n } catch {\n // skip malformed event\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n}\n\n/* ------------------------------------------------------------------ */\n/* Images */\n/* ------------------------------------------------------------------ */\n\nclass ImagesResource {\n constructor(private client: Sintaks) {}\n\n async generate(params: ImageGenerationParams): Promise<ImageGenerationResult> {\n return this.client.request<ImageGenerationResult>(\"POST\", \"/v1/images/generations\", {\n ...params,\n model: params.model ?? DEFAULT_IMAGE_MODEL,\n });\n }\n}\n\nclass ModelsResource {\n constructor(private client: Sintaks) {}\n\n /** Lists the active models served by the gateway (GET /v1/models). */\n async list(): Promise<ModelList> {\n return this.client.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QAER;AAAA,MACF;AAAA,IACF;AAAA,EACF,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACF;AAMA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAAoB,QAAiB;AAAjB;AAAA,EAAkB;AAAA,EAAlB;AAAA,EAEpB,MAAM,SAAS,QAA+D;AAC5E,WAAO,KAAK,OAAO,QAA+B,QAAQ,0BAA0B;AAAA,MAClF,GAAG;AAAA,MACH,OAAO,OAAO,SAAS;AAAA,IACzB,CAAC;AAAA,EACH;AACF;AAEA,IAAM,iBAAN,MAAqB;AAAA,EACnB,YAAoB,QAAiB;AAAjB;AAAA,EAAkB;AAAA,EAAlB;AAAA;AAAA,EAGpB,MAAM,OAA2B;AAC/B,WAAO,KAAK,OAAO,QAAmB,OAAO,YAAY;AAAA,EAC3D;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sintaksdev/sdk",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "TypeScript client for the sintaks.dev OpenAI-compatible AI API gateway. Top up in IDR, call chat and image models, pay per request.",
5
5
  "license": "MIT",
6
6
  "type": "module",