Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions src/resources/ai/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {
import { APIPromise } from '../../core/api-promise';
import { type Uploadable } from '../../core/uploads';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';

export class BaseAI extends APIResource {
static override readonly _key: readonly ['ai'] = Object.freeze(['ai'] as const);
Expand All @@ -61,7 +60,7 @@ export class BaseAI extends APIResource {
run(modelName: string, params: AIRunParams, options?: RequestOptions): APIPromise<AIRunResponse> {
const { account_id, ...body } = params;
return (
this._client.post(path`/accounts/${account_id}/ai/run/${modelName}`, {
this._client.post(`/accounts/${account_id}/ai/run/${modelName}`, {
body,
...options,
}) as APIPromise<{ result: AIRunResponse }>
Expand Down
26 changes: 26 additions & 0 deletions tests/api-resources/ai/ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ const runTests = (client: PartialCloudflare<{ ai: BaseAI }>) => {
};
describe('resource ai', () => runTests(client));
describe('resource ai (tree shakable, base)', () => runTests(partialClient));

test('run: keeps `/` in model name unencoded', async () => {
let capturedUrl: string | undefined;
const fetchSpy = (url: string | URL | Request, init?: RequestInit): Promise<Response> => {
capturedUrl = String(url);
return Promise.resolve(
new Response(JSON.stringify({}), { headers: { 'Content-Type': 'application/json' } }),
);
};

const client = new Cloudflare({
baseURL: 'http://localhost:5000/',
apiKey: '144c9defac04969c7bfad8efaa8ea194',
apiEmail: 'user@example.com',
fetch: fetchSpy,
});

await client.ai.run('@cf/meta/llama-3.3-70b-instruct-fp8-fast', {
account_id: '023e105f4ecef8ad9ca31a8372d0c353',
text: 'x',
});

expect(capturedUrl).toBe(
'http://localhost:5000/accounts/023e105f4ecef8ad9ca31a8372d0c353/ai/run/@cf/meta/llama-3.3-70b-instruct-fp8-fast',
);
});