This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathopenapi.ts
More file actions
156 lines (150 loc) · 3.55 KB
/
openapi.ts
File metadata and controls
156 lines (150 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* OpenAPI configuration
*/
import { OpenAPIHono, z } from '@hono/zod-openapi'
export const app = new OpenAPIHono()
export const openApiConfig = {
openapi: '3.1.0',
info: {
title: 'not-claude-code-emulator',
version: '1.0.0',
description: 'A Hono-based OAuth server for Anthropic API with Claude Code integration',
contact: {
name: 'API Support',
email: 'support@example.com',
},
},
servers: [
{
url: 'http://localhost:3000',
description: 'Local development server',
},
],
tags: [
{
name: 'Anthropic API',
description: 'Proxy endpoints for Anthropic Messages API',
},
{
name: 'Health',
description: 'Health check and status endpoints',
},
],
}
// Common schemas
export const ErrorSchema = z
.object({
error: z.object({
type: z.string().openapi({
description: 'Error type',
example: 'invalid_request_error',
}),
message: z.string().openapi({
description: 'Error message',
example: 'Invalid request parameters',
}),
}),
})
.openapi('ErrorResponse')
export const MessageRequestSchema = z
.object({
model: z.string().openapi({
description: 'Model ID',
example: 'claude-sonnet-4-5-20250929',
}),
max_tokens: z.number().int().positive().openapi({
description: 'Maximum tokens to generate',
example: 1024,
}),
messages: z
.array(
z.object({
role: z.enum(['user', 'assistant']).openapi({
description: 'Message role',
example: 'user',
}),
content: z.union([z.string(), z.array(z.any())]).openapi({
description: 'Message content',
example: 'Hello, Claude!',
}),
}),
)
.openapi({
description: 'Conversation messages',
}),
system: z
.union([z.string(), z.array(z.any())])
.optional()
.openapi({
description: 'System prompt',
example: 'You are a helpful assistant.',
}),
temperature: z.number().min(0).max(1).optional().openapi({
description: 'Sampling temperature',
example: 0.7,
}),
stream: z.boolean().optional().openapi({
description: 'Enable streaming response',
example: false,
}),
tools: z.array(z.any()).optional().openapi({
description: 'Available tools',
}),
tool_choice: z.any().optional().openapi({
description: 'Tool choice configuration',
}),
thinking: z
.object({
type: z.literal('enabled'),
budget_tokens: z.number().int().positive(),
})
.optional()
.openapi({
description: 'Thinking mode configuration',
}),
})
.openapi('MessageRequest')
export const MessageResponseSchema = z
.object({
id: z.string().openapi({
description: 'Message ID',
example: 'msg_01Xxxxxxxxxxxxxxxxx',
}),
type: z.literal('message').openapi({
description: 'Response type',
}),
role: z.literal('assistant').openapi({
description: 'Message role',
}),
model: z.string().openapi({
description: 'Model used',
example: 'claude-sonnet-4-5-20250929',
}),
content: z.array(z.any()).openapi({
description: 'Response content blocks',
}),
stop_reason: z
.enum(['end_turn', 'max_tokens', 'stop_sequence', 'tool_use'])
.nullable()
.openapi({
description: 'Reason for stopping',
}),
stop_sequence: z.string().nullable().openapi({
description: 'Stop sequence if applicable',
}),
usage: z
.object({
input_tokens: z.number().int().openapi({
description: 'Input tokens used',
example: 10,
}),
output_tokens: z.number().int().openapi({
description: 'Output tokens generated',
example: 100,
}),
})
.openapi({
description: 'Token usage statistics',
}),
})
.openapi('MessageResponse')