HTTP クライアント(通信プログラム)の不正な使い方を Output SDK ステップ内で修正します。 次のような場合に使用: - 追跡されていないリクエスト(通信要求)がある - エラーの詳しい内容が記録されていない - axios(通信ライブラリ)に関するエラーが出ている - HTTP 通信がログに記録されず、再試行されていない
Fix HTTP client misuse in Output SDK steps. Use when seeing untraced requests, missing error details, axios-related errors, or when HTTP calls aren't being properly logged and retried.
このスキルは、Output SDK の @outputai/http から提供される createKyClient を使わずに、axios や fetch などの HTTP クライアントを直接使用する場合に生じる問題を診断して修正します。Output SDK のクライアントを使うことで、リクエストの追跡、自動再試行、より良いエラー処理が実現できます。
axios、fetch、その他の HTTP クライアントを直接使うと、Output SDK の以下の機能がバイパスされてしまいます:
// 誤り: axios を使用
import axios from 'axios';
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const response = await axios.get( 'https://api.example.com/data' );
return response.data;
}
} );
// 誤り: fetch を使用
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const response = await fetch( 'https://api.example.com/data' );
return response.json();
}
} );
@outputai/http の createKyClient を使用してください:
import { z, step } from '@outputai/core';
import { createKyClient } from '@outputai/http';
export const fetchData = step( {
name: 'fetchData',
inputSchema: z.object( {
endpoint: z.string()
} ),
outputSchema: z.object( {
data: z.unknown()
} ),
fn: async input => {
const client = createKyClient( {
prefix: 'https://api.example.com'
} );
const data = await client.get( input.endpoint ).json();
return { data };
}
} );
import { createKyClient } from '@outputai/http';
const client = createKyClient( {
prefix: 'https://api.example.com',
timeout: 30000, // 30秒のタイムアウト
retry: {
limit: 3, // 最大3回再試行
methods: [ 'GET', 'POST' ], // 再試行対象のHTTPメソッド
statusCodes: [ 408, 500, 502, 503, 504 ] // 再試行をトリガーするステータスコード
},
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
} );
const data = await client.get( 'users/123' ).json();
const result = await client.post( 'users', {
json: {
name: 'John',
email: 'john@example.com'
}
} ).json();
const updated = await client.put( 'users/123', {
json: {
name: 'John Updated'
}
} ).json();
await client.delete( 'users/123' );
const data = await client.get( 'search', {
searchParams: {
q: 'query',
limit: 10
}
} ).json();
レスポンスのメタデータ(response.url、response.status、ヘッダーなど)だけを読む場合は、使用されないボディをキャンセルしてください。.json() や .text() などでボディを読むと、既に消費されます。
const response = await client.get( url );
try {
return response.url;
} finally {
await response.body?.cancel();
}
import axios from 'axios';
import { step } from '@outputai/core';
export const createUser = step( {
name: 'createUser',
fn: async input => {
try {
const response = await axios.post(
'https://api.example.com/users',
{ name: input.name, email: input.email },
{
headers: { 'Authorization': `Bearer ${process.env.API_KEY}` },
timeout: 30000
}
);
return response.data;
} catch ( error ) {
if ( axios.isAxiosError( error ) ) {
throw new Error( `API Error: ${error.response?.data?.message}` );
}
throw error;
}
}
} );
import { z, step } from '@outputai/core';
import { createKyClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
export const createUser = step( {
name: 'createUser',
inputSchema: z.object( {
name: z.string(),
email: z.string().email()
} ),
outputSchema: z.object( {
id: z.string(),
name: z.string(),
email: z.string()
} ),
fn: async input => {
const client = createKyClient( {
prefix: 'https://api.example.com',
timeout: 30000,
retry: { limit: 3 },
headers: {
'Authorization': `Bearer ${credentials.require( 'service.api_key' )}`
}
} );
const user = await client.post( 'users', {
json: {
name: input.name,
email: input.email
}
} ).json();
return user;
}
} );
Ky クライアントは構造化されたエラーハンドリングを提供します:
import { createKyClient, ky } from '@outputai/http';
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const client = createKyClient( { prefix: 'https://api.example.com' } );
try {
return await client.get( 'data' ).json();
} catch ( error ) {
if ( error instanceof ky.HTTPError ) {
// レスポンスの詳細情報にアクセス可能
const status = error.response.status;
const body = await error.response.json();
throw new Error( `API returned ${status}: ${body.message}` );
}
throw error;
}
}
} );
コードベース内で検索してください:
# axios のインポートを検索
grep -rn "from 'axios'\|from \"axios\"" src/
# fetch の呼び出しを検索
grep -rn "await fetch(" src/
# その他の HTTP ライブラリを検索
grep -rn "got\|node-fetch\|request\|superagent" src/
| オプション | 説明 | デフォルト |
|---|---|---|
prefix |
すべてのリクエストのベース URL | (必須) |
timeout |
リクエストのタイムアウト(ミリ秒) | 10000 |
retry.limit |
最大再試行回数 | 2 |
retry.methods |
再試行対象の HTTP メソッド | ['GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'] |
retry.statusCodes |
再試行をトリガーするステータスコード | [408, 413, 429, 500, 502, 503, 504] |
headers |
デフォルトヘッダー | {} |
createKyClient への移行後:
npx output workflow run <name> --input '<input>'npx output workflow debug <id> --jsonoutput-error-direct-io を参照output-services-check を参照output-dev-credentials を参照This skill helps diagnose and fix issues caused by using axios, fetch, or other HTTP clients directly instead of Output SDK's createKyClient from @outputai/http. The Output SDK client provides tracing, automatic retries, and better error handling.
You're seeing:
Using axios, fetch, or other HTTP clients directly bypasses Output SDK's:
// WRONG: Using axios
import axios from 'axios';
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const response = await axios.get( 'https://api.example.com/data' );
return response.data;
}
} );
// WRONG: Using fetch
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const response = await fetch( 'https://api.example.com/data' );
return response.json();
}
} );
Use createKyClient from @outputai/http:
import { z, step } from '@outputai/core';
import { createKyClient } from '@outputai/http';
export const fetchData = step( {
name: 'fetchData',
inputSchema: z.object( {
endpoint: z.string()
} ),
outputSchema: z.object( {
data: z.unknown()
} ),
fn: async input => {
const client = createKyClient( {
prefix: 'https://api.example.com'
} );
const data = await client.get( input.endpoint ).json();
return { data };
}
} );
import { createKyClient } from '@outputai/http';
const client = createKyClient( {
prefix: 'https://api.example.com',
timeout: 30000, // 30 second timeout
retry: {
limit: 3, // Retry up to 3 times
methods: [ 'GET', 'POST' ], // Which methods to retry
statusCodes: [ 408, 500, 502, 503, 504 ] // Which status codes trigger retry
},
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
} );
const data = await client.get( 'users/123' ).json();
const result = await client.post( 'users', {
json: {
name: 'John',
email: 'john@example.com'
}
} ).json();
const updated = await client.put( 'users/123', {
json: {
name: 'John Updated'
}
} ).json();
await client.delete( 'users/123' );
const data = await client.get( 'search', {
searchParams: {
q: 'query',
limit: 10
}
} ).json();
When code only reads metadata from a non-HEAD response, such as response.url, response.status, or headers, cancel the
unused body. Reading a body with .json(), .text(), etc. already consumes it.
const response = await client.get( url );
try {
return response.url;
} finally {
await response.body?.cancel();
}
import axios from 'axios';
import { step } from '@outputai/core';
export const createUser = step( {
name: 'createUser',
fn: async input => {
try {
const response = await axios.post(
'https://api.example.com/users',
{ name: input.name, email: input.email },
{
headers: { 'Authorization': `Bearer ${process.env.API_KEY}` },
timeout: 30000
}
);
return response.data;
} catch ( error ) {
if ( axios.isAxiosError( error ) ) {
throw new Error( `API Error: ${error.response?.data?.message}` );
}
throw error;
}
}
} );
import { z, step } from '@outputai/core';
import { createKyClient } from '@outputai/http';
import { credentials } from '@outputai/credentials';
export const createUser = step( {
name: 'createUser',
inputSchema: z.object( {
name: z.string(),
email: z.string().email()
} ),
outputSchema: z.object( {
id: z.string(),
name: z.string(),
email: z.string()
} ),
fn: async input => {
const client = createKyClient( {
prefix: 'https://api.example.com',
timeout: 30000,
retry: { limit: 3 },
headers: {
'Authorization': `Bearer ${credentials.require( 'service.api_key' )}`
}
} );
const user = await client.post( 'users', {
json: {
name: input.name,
email: input.email
}
} ).json();
return user;
}
} );
The Ky client provides structured error handling:
import { createKyClient, ky } from '@outputai/http';
export const fetchData = step( {
name: 'fetchData',
fn: async input => {
const client = createKyClient( { prefix: 'https://api.example.com' } );
try {
return await client.get( 'data' ).json();
} catch ( error ) {
if ( error instanceof ky.HTTPError ) {
// Access response details
const status = error.response.status;
const body = await error.response.json();
throw new Error( `API returned ${status}: ${body.message}` );
}
throw error;
}
}
} );
Search your codebase:
# Find axios imports
grep -rn "from 'axios'\|from \"axios\"" src/
# Find fetch calls
grep -rn "await fetch(" src/
# Find other HTTP libraries
grep -rn "got\|node-fetch\|request\|superagent" src/
| Option | Description | Default |
|---|---|---|
prefix |
Base URL for all requests | (required) |
timeout |
Request timeout in ms | 10000 |
retry.limit |
Max retry attempts | 2 |
retry.methods |
HTTP methods to retry | ['GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE'] |
retry.statusCodes |
Status codes to retry | [408, 413, 429, 500, 502, 503, 504] |
headers |
Default headers | {} |
After migrating to createKyClient:
npx output workflow run <name> --input '<input>'npx output workflow debug <id> --jsonoutput-error-direct-iooutput-services-checkoutput-dev-credentials原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。