diff --git a/src/resources/ai/ai.ts b/src/resources/ai/ai.ts index 102bcb2041d..773ecab20b9 100644 --- a/src/resources/ai/ai.ts +++ b/src/resources/ai/ai.ts @@ -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); @@ -61,7 +60,7 @@ export class BaseAI extends APIResource { run(modelName: string, params: AIRunParams, options?: RequestOptions): APIPromise { 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 }> diff --git a/tests/api-resources/ai/ai.test.ts b/tests/api-resources/ai/ai.test.ts index b9f49a46c03..03a29097955 100644 --- a/tests/api-resources/ai/ai.test.ts +++ b/tests/api-resources/ai/ai.test.ts @@ -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 => { + 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', + ); +});